java画直线,把直线画出来之后,JFrame里面的组件都不见了
packagetest;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassDe...
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Demo extends JFrame{
public static void main(String[] args) {
// TODO 自动生成的方法存根
new Demo();
}
public Demo(){
JLabel jl1=new JLabel("我是label1");
JLabel jl2=new JLabel("我是label2");
this.add(jl1);
this.add(jl2);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.CENTER));
}
public void paint(Graphics g)
{
g.drawLine(30,170,450,170);
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Demo extends JFrame{
public static void main(String[] args) {
// TODO 自动生成的方法存根
new Demo();
}
public Demo(){
JLabel jl1=new JLabel("我是label1");
JLabel jl2=new JLabel("我是label2");
this.add(jl1);
this.add(jl2);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.CENTER));
}
public void paint(Graphics g)
{
g.drawLine(30,170,450,170);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询