一段编好的JAVA程序,有许多错误 帮忙看看。谢谢了
+-数字一____×_____数字二=_______/加减乘除是按钮数字一和数字二是标签就是这样的题不过编出来的东西总有错误帮忙看看谢谢今天晚上就要了请快点如果过了时间答...
+
-
数字一____ ×_____数字二 =_______
/
加减乘除是按钮 数字一和数字二是标签
就是这样的题 不过编出来的东西 总有错误帮忙看看 谢谢
今天晚上就要了 请快点 如果过了时间 答案也就没用了,分我也会作废的谢谢
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class jiemian extends Applet implements ActionListener
{
Label Nname1=new Lable("数1");
Label Nname2=new Lable("数2");
TextField tnama1=new TextField();
TextField tnama2=new TextField();
TextField tnama3=new TextField();
Button btn1=new Button("+");
Button btn2=new Button("-");
Button btn3=new Button("*");
Button btn4=new Button("/");
Button btn5=new Button("=");
public void init(){
this.setLayout(null);
Nname1.setBounds(10,30,100,40);
Nname1.setFont(new Font("",Font.BOLD,40));
Nname1.setForeground(color.cyan);
Nname1.setBounds(10,30,80,40);
Nname1.setFont(new Font("",Font.BOLD,40));
add(Nname1);
Nname2.setBounds(370,30,100,40);
Nname2.setFont(new Font("",Font.BOLD,40));
Nname2.setForeground(color.cyan);
Nname2.setBounds(10,30,80,40);
Nname2.setFont(new Font("",Font.BOLD,40));
add(Nname2);
tname1.setBounds(120,30,200,40);
tname1.setFont(new Font("",Font.BOLD,40));
tname2.setBounds(480,30,200,40);
tname2.setFont(new Font("",Font.BOLD,40));
tname3.setBounds(730,30,200,40);
tname3.setFont(new Font("",Font.BOLD,40));
add(tname1);
add(tname2);
add(tname3);
btn1.setBounds(330,0,30,30);
btn1.setFont(new Font("",Font.BOLD,20));
btn2.setBounds(330,40,30,30);
btn2.setFont(new Font("",Font.BOLD,20));
btn3.setBounds(330,80,30,30);
btn3.setFont(new Font("",Font.BOLD,20));
btn4.setBounds(330,120,30,30);
btn4.setFont(new Font("",Font.BOLD,20));
btn5.setBounds(690,30,30,30);
btn5.setFont(new Font("",Font.BOLD,20));
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
btn1.addActionListeners(this);
btn2.addActionListeners(this);
btn3.addActionListeners(this);
btn4.addActionListeners(this);
btn5.addActionListeners(this);
}
pubilc void actionPorformed(ActionEvent e){
String cmd=e.getActioncommand();
if(cmd.equles(bnt5)){
if(cmd.equles(bnt1)){
String s=+(tname1.getText()+tname2.getText());
}
if(cmd.equles(bnt2)){
String s=+(tname1.getText()-tname2.getText());
}
if(cmd.equles(bnt3)){
String s=+(tname1.getText()*tname2.getText());
}
if(cmd.equles(bnt4)){
String s=+(tname1.getText()/tname2.getText());
}
}
}
} 展开
-
数字一____ ×_____数字二 =_______
/
加减乘除是按钮 数字一和数字二是标签
就是这样的题 不过编出来的东西 总有错误帮忙看看 谢谢
今天晚上就要了 请快点 如果过了时间 答案也就没用了,分我也会作废的谢谢
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class jiemian extends Applet implements ActionListener
{
Label Nname1=new Lable("数1");
Label Nname2=new Lable("数2");
TextField tnama1=new TextField();
TextField tnama2=new TextField();
TextField tnama3=new TextField();
Button btn1=new Button("+");
Button btn2=new Button("-");
Button btn3=new Button("*");
Button btn4=new Button("/");
Button btn5=new Button("=");
public void init(){
this.setLayout(null);
Nname1.setBounds(10,30,100,40);
Nname1.setFont(new Font("",Font.BOLD,40));
Nname1.setForeground(color.cyan);
Nname1.setBounds(10,30,80,40);
Nname1.setFont(new Font("",Font.BOLD,40));
add(Nname1);
Nname2.setBounds(370,30,100,40);
Nname2.setFont(new Font("",Font.BOLD,40));
Nname2.setForeground(color.cyan);
Nname2.setBounds(10,30,80,40);
Nname2.setFont(new Font("",Font.BOLD,40));
add(Nname2);
tname1.setBounds(120,30,200,40);
tname1.setFont(new Font("",Font.BOLD,40));
tname2.setBounds(480,30,200,40);
tname2.setFont(new Font("",Font.BOLD,40));
tname3.setBounds(730,30,200,40);
tname3.setFont(new Font("",Font.BOLD,40));
add(tname1);
add(tname2);
add(tname3);
btn1.setBounds(330,0,30,30);
btn1.setFont(new Font("",Font.BOLD,20));
btn2.setBounds(330,40,30,30);
btn2.setFont(new Font("",Font.BOLD,20));
btn3.setBounds(330,80,30,30);
btn3.setFont(new Font("",Font.BOLD,20));
btn4.setBounds(330,120,30,30);
btn4.setFont(new Font("",Font.BOLD,20));
btn5.setBounds(690,30,30,30);
btn5.setFont(new Font("",Font.BOLD,20));
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
btn1.addActionListeners(this);
btn2.addActionListeners(this);
btn3.addActionListeners(this);
btn4.addActionListeners(this);
btn5.addActionListeners(this);
}
pubilc void actionPorformed(ActionEvent e){
String cmd=e.getActioncommand();
if(cmd.equles(bnt5)){
if(cmd.equles(bnt1)){
String s=+(tname1.getText()+tname2.getText());
}
if(cmd.equles(bnt2)){
String s=+(tname1.getText()-tname2.getText());
}
if(cmd.equles(bnt3)){
String s=+(tname1.getText()*tname2.getText());
}
if(cmd.equles(bnt4)){
String s=+(tname1.getText()/tname2.getText());
}
}
}
} 展开
展开全部
有点乱啊
看了会没法下手
不好意思
看了会没法下手
不好意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的代码逻辑还有些问题,我又改了一下,现在能用了
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class jiemian extends Applet implements ActionListener
{ int flag=0;
Label Nname1=new Label("数1");
Label Nname2=new Label("数2");
TextField tname1=new TextField();
TextField tname2=new TextField();
TextField tname3=new TextField();
Button btn1=new Button("+");
Button btn2=new Button("-");
Button btn3=new Button("*");
Button btn4=new Button("/");
Button btn5=new Button("=");
public void init(){
this.setLayout(null);
Nname1.setBounds(10,30,100,40);
Nname1.setFont(new Font("",Font.BOLD,40));
Nname1.setForeground(Color.cyan);
Nname1.setBounds(10,30,80,40);
Nname1.setFont(new Font("",Font.BOLD,40));
add(Nname1);
Nname2.setBounds(370,30,100,40);
Nname2.setFont(new Font("",Font.BOLD,40));
Nname2.setForeground(Color.cyan);
Nname2.setBounds(10,30,80,40);
Nname2.setFont(new Font("",Font.BOLD,40));
add(Nname2);
tname1.setBounds(120,30,200,40);
tname1.setFont(new Font("",Font.BOLD,40));
tname2.setBounds(480,30,200,40);
tname2.setFont(new Font("",Font.BOLD,40));
tname3.setBounds(730,30,200,40);
tname3.setFont(new Font("",Font.BOLD,40));
add(tname1);
add(tname2);
add(tname3);
btn1.setBounds(330,0,30,30);
btn1.setFont(new Font("",Font.BOLD,20));
btn2.setBounds(330,40,30,30);
btn2.setFont(new Font("",Font.BOLD,20));
btn3.setBounds(330,80,30,30);
btn3.setFont(new Font("",Font.BOLD,20));
btn4.setBounds(330,120,30,30);
btn4.setFont(new Font("",Font.BOLD,20));
btn5.setBounds(690,30,30,30);
btn5.setFont(new Font("",Font.BOLD,20));
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn1.setActionCommand("btn1");
btn2.setActionCommand("btn2");
btn3.setActionCommand("btn3");
btn4.setActionCommand("btn4");
btn5.setActionCommand("btn5");
}
public void actionPerformed(ActionEvent e){
String cmd=e.getActionCommand();
if(cmd.equals("btn5")){
if(flag==1){
String s=String.valueOf(Integer.parseInt(tname1.getText())+Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==2){
String s=String.valueOf(Integer.parseInt(tname1.getText())-Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==3){
String s=String.valueOf(Integer.parseInt(tname1.getText())*Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==4){
String s=String.valueOf(Integer.parseInt(tname1.getText())/Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
}else if(cmd.equals("btn1")){
flag=1;
}else if(cmd.equals("btn2")){
flag=2;
}else if(cmd.equals("btn3")){
flag=3;
}else if(cmd.equals("btn4")){
flag=4;
}
}
/* public static void main(String ss[]){
jiemian j=new jiemian();
j.setVisible(true);
}*/
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class jiemian extends Applet implements ActionListener
{ int flag=0;
Label Nname1=new Label("数1");
Label Nname2=new Label("数2");
TextField tname1=new TextField();
TextField tname2=new TextField();
TextField tname3=new TextField();
Button btn1=new Button("+");
Button btn2=new Button("-");
Button btn3=new Button("*");
Button btn4=new Button("/");
Button btn5=new Button("=");
public void init(){
this.setLayout(null);
Nname1.setBounds(10,30,100,40);
Nname1.setFont(new Font("",Font.BOLD,40));
Nname1.setForeground(Color.cyan);
Nname1.setBounds(10,30,80,40);
Nname1.setFont(new Font("",Font.BOLD,40));
add(Nname1);
Nname2.setBounds(370,30,100,40);
Nname2.setFont(new Font("",Font.BOLD,40));
Nname2.setForeground(Color.cyan);
Nname2.setBounds(10,30,80,40);
Nname2.setFont(new Font("",Font.BOLD,40));
add(Nname2);
tname1.setBounds(120,30,200,40);
tname1.setFont(new Font("",Font.BOLD,40));
tname2.setBounds(480,30,200,40);
tname2.setFont(new Font("",Font.BOLD,40));
tname3.setBounds(730,30,200,40);
tname3.setFont(new Font("",Font.BOLD,40));
add(tname1);
add(tname2);
add(tname3);
btn1.setBounds(330,0,30,30);
btn1.setFont(new Font("",Font.BOLD,20));
btn2.setBounds(330,40,30,30);
btn2.setFont(new Font("",Font.BOLD,20));
btn3.setBounds(330,80,30,30);
btn3.setFont(new Font("",Font.BOLD,20));
btn4.setBounds(330,120,30,30);
btn4.setFont(new Font("",Font.BOLD,20));
btn5.setBounds(690,30,30,30);
btn5.setFont(new Font("",Font.BOLD,20));
add(btn1);
add(btn2);
add(btn3);
add(btn4);
add(btn5);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn1.setActionCommand("btn1");
btn2.setActionCommand("btn2");
btn3.setActionCommand("btn3");
btn4.setActionCommand("btn4");
btn5.setActionCommand("btn5");
}
public void actionPerformed(ActionEvent e){
String cmd=e.getActionCommand();
if(cmd.equals("btn5")){
if(flag==1){
String s=String.valueOf(Integer.parseInt(tname1.getText())+Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==2){
String s=String.valueOf(Integer.parseInt(tname1.getText())-Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==3){
String s=String.valueOf(Integer.parseInt(tname1.getText())*Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
if(flag==4){
String s=String.valueOf(Integer.parseInt(tname1.getText())/Integer.parseInt(tname2.getText()));
tname3.setText(s);
}
}else if(cmd.equals("btn1")){
flag=1;
}else if(cmd.equals("btn2")){
flag=2;
}else if(cmd.equals("btn3")){
flag=3;
}else if(cmd.equals("btn4")){
flag=4;
}
}
/* public static void main(String ss[]){
jiemian j=new jiemian();
j.setVisible(true);
}*/
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询