Java 萌新求助。。为什么这个运行不了
packageaction1;importjavax.swing.*;importjava.awt.*;publicclassMyDraw{JFrameframe;pub...
package action1;
import javax.swing.*;
import java.awt.*;
public class MyDraw {
JFrame frame;
public static void main (String args){
MyDraw d=new MyDraw();
d.go();
}
public void go(){
frame= new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDraw1 de =new MyDraw1();
frame.getContentPane().add(BorderLayout.CENTER,de);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
class MyDraw1 extends JPanel{
public void paintComponent(Graphics g){
g.setColor(Color.red);
g.fillRect(20, 50, 100, 100);
}
} 展开
import javax.swing.*;
import java.awt.*;
public class MyDraw {
JFrame frame;
public static void main (String args){
MyDraw d=new MyDraw();
d.go();
}
public void go(){
frame= new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDraw1 de =new MyDraw1();
frame.getContentPane().add(BorderLayout.CENTER,de);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
class MyDraw1 extends JPanel{
public void paintComponent(Graphics g){
g.setColor(Color.red);
g.fillRect(20, 50, 100, 100);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询