package my_struct;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField;import java.awt.EventQueue;import java.awt.Font;import java.awt.Graphics;import java.awt.Color;import java.awt.Graphics2D;import java.awt.Point;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionAdapter;public class Gaosi extends JFrame{private static Point origin;Gaosi frame=this;public static void main(String[] args){EventQueue.invokeLater(new Runnable() {public void run() {try {Gaosi frame = new Gaosi();frame.setVisible(true);}catch (Exception e) {e.printStackTrace();}}});}public Gaosi(){super();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLocationRelativeTo(null);setBounds(300,100,500,460);this.setUndecorated(true);com.sun.awt.AWTUtilities.setWindowOpaque(frame,false);JPanel pane=new JPanel(){public void paint(Graphics g){super.paint(g);g.setColor(new Color(25,205,10));g.fillRoundRect(0, 0, getWidth(),getHeight(),80,80);Graphics2D graphics = (Graphics2D) getGraphics();setFont(new Font("微软雅黑",Font.BOLD,18));String str = "主元素高斯消去算法";graphics.drawString(str,156,36);}};this.setContentPane(pane);pane.setLayout(null);JTextField text1=new JTextField();text1.setBounds(150,300,50,22);pane.add(text1);this.origin=new Point();this.addMouseListener(new MouseAdapter(){public void mousePressed(MouseEvent e){origin.x = e.getX();origin.y = e.getY();}//窗体上单击鼠标右键关闭程序public void mouseClicked(MouseEvent e) {if(e.getButton()==MouseEvent.BUTTON3)System.exit(0);}});this.addMouseMotionListener(new MouseMotionAdapter(){public void mouseDragged(MouseEvent e){ //鼠标拖动Point p = getLocation();setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y );}});com.sun.awt.AWTUtilities.setWindowOpacity(frame,(float)0.6);}}public void paint(Graphics g){super.paint(g);改成:public void paintComponent(Graphics g){super.paintComponent(g);改用这种方法也不能显示组件!
1 回答
jeck猫
TA贡献1909条经验 获得超7个赞
public void paint(Graphics g){
super.paint(g);
改成:
public void paintComponent(Graphics g){
super.paintComponent(g);
添加回答
举报
0/150
提交
取消