主题:求一道JAVA题的答案
import java.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class c1_0 extends JApplet implements ActionListener
{
Container cp=getContentPane();
JButton bt1=new JButton();
JButton bt2=new JButton();
JButton bt3=new JButton();
public void init()
{ bt1.setRolloverEnabled(true);
bt2.setRolloverEnabled(true);
bt3.setRolloverEnabled(true);
bt1.setText("画圆");
bt2.setText("画直线");
bt3.setText("画椭圆");
bt1.setHorizontalTextPosition(JLabel.CENTER);
bt1.setVerticalTextPosition(JLabel.BOTTOM);
bt2.setHorizontalTextPosition(JLabel.CENTER);
bt2.setVerticalTextPosition(JLabel.BOTTOM);
bt3.setHorizontalTextPosition(JLabel.CENTER);
bt3.setVerticalTextPosition(JLabel.BOTTOM);
cp.add(bt1,BorderLayout.SOUTH);
cp.add(bt2,BorderLayout.CENTER);
cp.add(bt3,BorderLayout.NORTH);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void paint(Graphics g )
{
Graphics2D g2=(Graphics2D)g;
Ellipse2D.Double e1=new Ellipse2D.Double(100,100,50,50);
Line2D.Double l1=new Line2D.Double(100,100,200,200);
Ellipse2D.Double e2=new Ellipse2D.Double(300,300,60,40);
g2.draw(e1);
g2.draw(l1);
g2.draw(e2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt1) repaint();
if(e.getSource()==bt2) repaint();
if(e.getSource()==bt3)repaint();
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;
public class c1_0 extends JApplet implements ActionListener
{
Container cp=getContentPane();
JButton bt1=new JButton();
JButton bt2=new JButton();
JButton bt3=new JButton();
public void init()
{ bt1.setRolloverEnabled(true);
bt2.setRolloverEnabled(true);
bt3.setRolloverEnabled(true);
bt1.setText("画圆");
bt2.setText("画直线");
bt3.setText("画椭圆");
bt1.setHorizontalTextPosition(JLabel.CENTER);
bt1.setVerticalTextPosition(JLabel.BOTTOM);
bt2.setHorizontalTextPosition(JLabel.CENTER);
bt2.setVerticalTextPosition(JLabel.BOTTOM);
bt3.setHorizontalTextPosition(JLabel.CENTER);
bt3.setVerticalTextPosition(JLabel.BOTTOM);
cp.add(bt1,BorderLayout.SOUTH);
cp.add(bt2,BorderLayout.CENTER);
cp.add(bt3,BorderLayout.NORTH);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void paint(Graphics g )
{
Graphics2D g2=(Graphics2D)g;
Ellipse2D.Double e1=new Ellipse2D.Double(100,100,50,50);
Line2D.Double l1=new Line2D.Double(100,100,200,200);
Ellipse2D.Double e2=new Ellipse2D.Double(300,300,60,40);
g2.draw(e1);
g2.draw(l1);
g2.draw(e2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bt1) repaint();
if(e.getSource()==bt2) repaint();
if(e.getSource()==bt3)repaint();
}
}