java 用绘图画不出图
RT请高手门看下吧,照书上打的就是出不来纠结死了importjava.awt.*;importjavax.swing.*;publicclassDrawingTest{p...
RT 请高手门看下吧,照书上打的就是出不来 纠结死了
import java.awt.*;
import javax.swing.*;
public class DrawingTest {
public static void main(String[] args) {
JFrame jf;
Container contentPane;
Graphics g;
jf = new JFrame("My First Rectangle");
jf.setSize(500,500);
jf.setLocation(100,100);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = jf.getContentPane();
g = contentPane.getGraphics();
g.setColor(Color.BLUE);
g.fillRect(150, 150, 100, 30);
}
} 展开
import java.awt.*;
import javax.swing.*;
public class DrawingTest {
public static void main(String[] args) {
JFrame jf;
Container contentPane;
Graphics g;
jf = new JFrame("My First Rectangle");
jf.setSize(500,500);
jf.setLocation(100,100);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = jf.getContentPane();
g = contentPane.getGraphics();
g.setColor(Color.BLUE);
g.fillRect(150, 150, 100, 30);
}
} 展开
展开全部
你的用法有误,应该如下
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawingTest {
public static void main(String[] args) {
JFrame jf;
Container contentPane;
Graphics g;
jf = new JFrame("My First Rectangle") {
@Override
public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(150, 150, 100, 30);
}
};
jf.setSize(500,500);
jf.setLocation(100,100);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawingTest {
public static void main(String[] args) {
JFrame jf;
Container contentPane;
Graphics g;
jf = new JFrame("My First Rectangle") {
@Override
public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(150, 150, 100, 30);
}
};
jf.setSize(500,500);
jf.setLocation(100,100);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |