关于在java的panel中按一个按钮之后进行绘图的问题
我编了一个程序但是有问题麻烦大家帮我看一下先谢谢了importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;...
我编了一个程序
但是有问题
麻烦大家帮我看一下
先谢谢了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FrameDemo extends Frame
{
FrameDemo(String title)
{
super(title);
setSize(500,500);
setLocation(100,100);
setLayout(new GridLayout(0,2));
LinePanel1 lp1=new LinePanel1();
LinePanel2 lp2=new LinePanel2();
add(lp1);
add(lp2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public class LinePanel1 extends Panel
{
final boolean st;
public void paint(Graphics g)
{
if(st==true)
{
g.drawLine(0,0,10,10);
}
}
LinePanel1()
{
Button bt1=new Button("1");
bt1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
}
public boolean setSt()
{
st=true;
}
});
}
}
public class LinePanel2 extends Panel
{
public void paint(Graphics g)
{
g.drawLine(0,0,10,10);
}
}
public static void main(String args[])
{
FrameDemo f=new FrameDemo("FrameDemo");
f.show();
}
}
谢谢!!! 展开
但是有问题
麻烦大家帮我看一下
先谢谢了
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FrameDemo extends Frame
{
FrameDemo(String title)
{
super(title);
setSize(500,500);
setLocation(100,100);
setLayout(new GridLayout(0,2));
LinePanel1 lp1=new LinePanel1();
LinePanel2 lp2=new LinePanel2();
add(lp1);
add(lp2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public class LinePanel1 extends Panel
{
final boolean st;
public void paint(Graphics g)
{
if(st==true)
{
g.drawLine(0,0,10,10);
}
}
LinePanel1()
{
Button bt1=new Button("1");
bt1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
}
public boolean setSt()
{
st=true;
}
});
}
}
public class LinePanel2 extends Panel
{
public void paint(Graphics g)
{
g.drawLine(0,0,10,10);
}
}
public static void main(String args[])
{
FrameDemo f=new FrameDemo("FrameDemo");
f.show();
}
}
谢谢!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询