请问一下在java的一个panel中如何去绘制一条直线,谢谢
发布网友
发布时间:2022-04-23 06:38
我来回答
共1个回答
热心网友
时间:2022-06-16 18:44
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FrameDemo extends JFrame {
private JPanel jp;
public FrameDemo(){
jp=new JPanel();
linePanel lp = new linePanel();
this.add(jp);
this.add(lp);
this.setSize(300, 300);
this.setVisible(true);
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
public class linePanel extends JPanel{
public void paint(Graphics g){
g.drawLine(0,0,10,20);
}
}
public static void main(String[] args) {
FrameDemo fd=new FrameDemo();
}
}