java按钮画图问题
importjava.applet.*;importjava.awt.*;importjava.awt.event.*;publicclasshuaextendsAppl...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class hua extends Applet implements ActionListener{
String w="";
String h="";
Label lw=new Label("请输入宽");
TextField tw=new TextField(5);
Label lh=new Label("请输入长");
TextField th=new TextField(5);
boolean good=true;
Button btnyuan=new Button("做个椭圆");
Button btnxing=new Button("做个矩形");
public void init(){
add(lw);add(tw);
add(lh);add(th);
add(btnyuan);
add(btnxing);
btnyuan.addActionListener(this);
btnxing.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
w=String(tw.getText());
h=String(th.getText());
if(e.getSource()==btnyuan)
good=true;
else
good=false;
repaint();
}
public void paint(Graphics g){
if(good){
g.drawOval(200,200,w,h);}
else{
g.drawRect(200,200,w,h);}
}
}
有好心人可以帮我改好它吗,就是类型错了,不知道怎么改哦5555555555 展开
import java.awt.*;
import java.awt.event.*;
public class hua extends Applet implements ActionListener{
String w="";
String h="";
Label lw=new Label("请输入宽");
TextField tw=new TextField(5);
Label lh=new Label("请输入长");
TextField th=new TextField(5);
boolean good=true;
Button btnyuan=new Button("做个椭圆");
Button btnxing=new Button("做个矩形");
public void init(){
add(lw);add(tw);
add(lh);add(th);
add(btnyuan);
add(btnxing);
btnyuan.addActionListener(this);
btnxing.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
w=String(tw.getText());
h=String(th.getText());
if(e.getSource()==btnyuan)
good=true;
else
good=false;
repaint();
}
public void paint(Graphics g){
if(good){
g.drawOval(200,200,w,h);}
else{
g.drawRect(200,200,w,h);}
}
}
有好心人可以帮我改好它吗,就是类型错了,不知道怎么改哦5555555555 展开
1个回答
展开全部
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class hua extends Applet implements ActionListener {
String w = "";
String h = "";
Label lw = new Label("请输入宽");
TextField tw = new TextField(5);
Label lh = new Label("请输入长");
TextField th = new TextField(5);
boolean good = true;
Button btnyuan = new Button("做个椭圆");
Button btnxing = new Button("做个矩形");
public void init() {
add(lw);
add(tw);
add(lh);
add(th);
add(btnyuan);
add(btnxing);
btnyuan.addActionListener(this);
btnxing.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
w = tw.getText();
h = th.getText();
if (e.getSource() == btnyuan)
good = true;
else
good = false;
repaint();
}
public void paint(Graphics g) {
if (good) {
g.drawOval(200, 200, Integer.parseInt(w), Integer.parseInt(h));
} else {
g.drawRect(200, 200, Integer.parseInt(w), Integer.parseInt(h));
}
}
}
import java.awt.*;
import java.awt.event.*;
public class hua extends Applet implements ActionListener {
String w = "";
String h = "";
Label lw = new Label("请输入宽");
TextField tw = new TextField(5);
Label lh = new Label("请输入长");
TextField th = new TextField(5);
boolean good = true;
Button btnyuan = new Button("做个椭圆");
Button btnxing = new Button("做个矩形");
public void init() {
add(lw);
add(tw);
add(lh);
add(th);
add(btnyuan);
add(btnxing);
btnyuan.addActionListener(this);
btnxing.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
w = tw.getText();
h = th.getText();
if (e.getSource() == btnyuan)
good = true;
else
good = false;
repaint();
}
public void paint(Graphics g) {
if (good) {
g.drawOval(200, 200, Integer.parseInt(w), Integer.parseInt(h));
} else {
g.drawRect(200, 200, Integer.parseInt(w), Integer.parseInt(h));
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询