一个关于JAVA界面的程序
程序目的是设置两个按钮1,2,点击1的时候画一个圆,点击2的时候画一个正方形,谁可以帮忙改一改这个程序啊?importjava.awt.*;importjava.appl...
程序目的是设置两个按钮1,2,点击1的时候画一个圆,点击2的时候画一个正方形,谁可以帮忙改一改这个程序啊?
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class test extends JApplet implements ActionListener
{
JButton bt1=new JButton("1");
JButton bt2=new JButton("2");
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout(FlowLayout.CENTER,300,2));
cp.add(bt1);
cp.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
public void paint(Graphics g)
{
if((e.getActionCommand()).equals("1"))
{
g.drawArc(100,100,50,50,0,360,g.open);
}
if((e.getActionCommand()).equals("2"))
{
g.drawRect(100,100,50,50);
}
}
}
} 展开
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class test extends JApplet implements ActionListener
{
JButton bt1=new JButton("1");
JButton bt2=new JButton("2");
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout(FlowLayout.CENTER,300,2));
cp.add(bt1);
cp.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
public void paint(Graphics g)
{
if((e.getActionCommand()).equals("1"))
{
g.drawArc(100,100,50,50,0,360,g.open);
}
if((e.getActionCommand()).equals("2"))
{
g.drawRect(100,100,50,50);
}
}
}
} 展开
2个回答
展开全部
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class test extends JApplet implements ActionListener
{
JButton bt1=new JButton("1");
JButton bt2=new JButton("2");
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout(FlowLayout.CENTER,300,2));
cp.add(bt1);
cp.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Graphics g=getGraphics();
//public void paint(Graphics g)
// {
if((e.getActionCommand()).equals("1"))
{
g.drawOval(100,100,50,50);
//g.drawArc(100,100,50,50,0,360,g.open);
}
if((e.getActionCommand()).equals("2"))
{
g.drawRect(100,100,50,50);
}
// }
}
}
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class test extends JApplet implements ActionListener
{
JButton bt1=new JButton("1");
JButton bt2=new JButton("2");
public void init()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout(FlowLayout.CENTER,300,2));
cp.add(bt1);
cp.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Graphics g=getGraphics();
//public void paint(Graphics g)
// {
if((e.getActionCommand()).equals("1"))
{
g.drawOval(100,100,50,50);
//g.drawArc(100,100,50,50,0,360,g.open);
}
if((e.getActionCommand()).equals("2"))
{
g.drawRect(100,100,50,50);
}
// }
}
}
展开全部
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class test extends JApplet implements ActionListener {
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
int button = 0;
Graphics g;
public void init() {
setLayout(new FlowLayout(FlowLayout.CENTER, 300, 2));
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void paint(Graphics g) {
if (button==1) {
g.drawArc(100, 100, 50, 50, 0, 360);
}
if (button==2) {
g.drawRect(100, 100, 50, 50);
}
}
public void paintRect()
{
button = 1;
repaint();
}
public void paintArc()
{
button = 2;
repaint();
}
public void actionPerformed(ActionEvent e) {
if ((e.getActionCommand()).equals("1")) {
paintArc();
}
if ((e.getActionCommand()).equals("2")) {
paintRect();
}
}
public static void main(String[] args) {
test a = new test ();
a.init();
}
}
import javax.swing.*;
import java.awt.event.*;
public class test extends JApplet implements ActionListener {
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
int button = 0;
Graphics g;
public void init() {
setLayout(new FlowLayout(FlowLayout.CENTER, 300, 2));
add(bt1);
add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
}
public void paint(Graphics g) {
if (button==1) {
g.drawArc(100, 100, 50, 50, 0, 360);
}
if (button==2) {
g.drawRect(100, 100, 50, 50);
}
}
public void paintRect()
{
button = 1;
repaint();
}
public void paintArc()
{
button = 2;
repaint();
}
public void actionPerformed(ActionEvent e) {
if ((e.getActionCommand()).equals("1")) {
paintArc();
}
if ((e.getActionCommand()).equals("2")) {
paintRect();
}
}
public static void main(String[] args) {
test a = new test ();
a.init();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询