关于JAVA的Graphics
麻烦帮忙看看下面这段小程序为什么画不出直线???importjavax.swing.*;importjava.awt.BorderLayout;importjava.aw...
麻烦帮忙看看下面这段小程序为什么画不出直线???
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
public class TestPaintComponent2 extends JFrame {
NewPanel2 myPanel=new NewPanel2();
public TestPaintComponent2() {
add(myPanel);
}
public static void main(String[] args) {
TestPaintComponent2 frame = new TestPaintComponent2();
frame.setTitle("TestPanelDrawing");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 100);
frame.setVisible(true);
Graphics g=frame.myPanel.getGraphics();
g.drawLine(0, 60, 50, 60);
}
}
class NewPanel2 extends JPanel {
NewPanel2(){
JLabel jlbBanner=new JLabel("Banner");
add(jlbBanner);
}
} 展开
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
public class TestPaintComponent2 extends JFrame {
NewPanel2 myPanel=new NewPanel2();
public TestPaintComponent2() {
add(myPanel);
}
public static void main(String[] args) {
TestPaintComponent2 frame = new TestPaintComponent2();
frame.setTitle("TestPanelDrawing");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 100);
frame.setVisible(true);
Graphics g=frame.myPanel.getGraphics();
g.drawLine(0, 60, 50, 60);
}
}
class NewPanel2 extends JPanel {
NewPanel2(){
JLabel jlbBanner=new JLabel("Banner");
add(jlbBanner);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询