关于JAVA Graphics类绘图的,程序在下面,求高手看看,为什么在窗口没把图画出来。是图消失了还是没画出来
packagechapter5;importjava.awt.Container;importjava.awt.Graphics;importjavax.swing.JF...
package chapter5;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
public class chapter02 {
public static void main(String[] args) {
JFrame win;
Container contentPane;
Graphics g;
win=new JFrame("The Clock");
win.setSize(300,200);
win.setLocation(100,100);
win.setVisible(true);
contentPane=win.getContentPane();
g=contentPane.getGraphics();
g.drawRect(50,50,100,30);
}
} 展开
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
public class chapter02 {
public static void main(String[] args) {
JFrame win;
Container contentPane;
Graphics g;
win=new JFrame("The Clock");
win.setSize(300,200);
win.setLocation(100,100);
win.setVisible(true);
contentPane=win.getContentPane();
g=contentPane.getGraphics();
g.drawRect(50,50,100,30);
}
} 展开
2个回答
展开全部
这样子画
package chapter5;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class chapter02 {
public static void main(String[] args) {
JFrame win;
Container contentPane;
Graphics g;
win=new JFrame("The Clock");
win.setSize(300,200);
win.setLocation(100,100);
win.setVisible(true);
JPanel imagePanel=new JPanel(){
public void paint(Graphics g){
super.paint(g);
g.drawRect(50, 50, 100, 30);
}
};
win.setContentPane(imagePanel);
}
}
package chapter5;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class chapter02 {
public static void main(String[] args) {
JFrame win;
Container contentPane;
Graphics g;
win=new JFrame("The Clock");
win.setSize(300,200);
win.setLocation(100,100);
win.setVisible(true);
JPanel imagePanel=new JPanel(){
public void paint(Graphics g){
super.paint(g);
g.drawRect(50, 50, 100, 30);
}
};
win.setContentPane(imagePanel);
}
}
追问
非常感谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询