谁能帮我用java编写一个程序啊??
用菜单和按钮来控制绘图功能要求:实现简单绘图功能,具体要求:画直线,画空心或实心椭圆、画空心或实心矩形、画多边形(图形的位置和大小可在程序中设定)。...
用菜单和按钮来控制绘图 功能要求:实现简单绘图功能,具体要求:画直线,画空心或实心椭圆、画空心或实心矩形、画多边形(图形的位置和大小可在程序中设定)。
展开
1个回答
展开全部
package com.zhh.test;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JB extends JFrame implements ActionListener
{
private JTextField Input1,Input2,Input3;
private JButton btnOK;
private static final String OK="计算";
private JTextField ShowAnswer;
public JB(String strTitle)
{
super(strTitle);
Container c=getContentPane();
c.setLayout(new FlowLayout());
Input1=new JTextField(4);
Input2=new JTextField(4);
Input3=new JTextField(4);
ShowAnswer=new JTextField(4);
btnOK=new JButton(OK);
c.add(new JLabel("请输入待计算的两个数据:"));
c.add(Input1);
c.add(Input2);
c.add(new JLabel("请输入计算符(1 for + ,2 for - ,3 for * ,4 for / ):"));
c.add(Input3);
c.add(new JLabel("计算结果:"));
c.add(ShowAnswer);
c.add(btnOK);
btnOK.addActionListener(this);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setSize(310,100);
this.setVisible(true);
}
public static void main(String[] args)
{
new JB("JButtonTest Testing!!!");
}
public void actionPerformed(ActionEvent e){
int num4 = 0;
int num1=Integer.parseInt(Input1.getText());
int num2=Integer.parseInt(Input2.getText());
int num3=Integer.parseInt(Input3.getText());
if(num3==1){ num4=num1+num2 ;}
if(num3==2){ num4=num1-num2 ;}
if(num3==3){ num4=num1*num2 ;}
if(num3==4){ num4=num1/num2 ;}
ShowAnswer.setText(String.valueOf(num4));
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JB extends JFrame implements ActionListener
{
private JTextField Input1,Input2,Input3;
private JButton btnOK;
private static final String OK="计算";
private JTextField ShowAnswer;
public JB(String strTitle)
{
super(strTitle);
Container c=getContentPane();
c.setLayout(new FlowLayout());
Input1=new JTextField(4);
Input2=new JTextField(4);
Input3=new JTextField(4);
ShowAnswer=new JTextField(4);
btnOK=new JButton(OK);
c.add(new JLabel("请输入待计算的两个数据:"));
c.add(Input1);
c.add(Input2);
c.add(new JLabel("请输入计算符(1 for + ,2 for - ,3 for * ,4 for / ):"));
c.add(Input3);
c.add(new JLabel("计算结果:"));
c.add(ShowAnswer);
c.add(btnOK);
btnOK.addActionListener(this);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
this.setSize(310,100);
this.setVisible(true);
}
public static void main(String[] args)
{
new JB("JButtonTest Testing!!!");
}
public void actionPerformed(ActionEvent e){
int num4 = 0;
int num1=Integer.parseInt(Input1.getText());
int num2=Integer.parseInt(Input2.getText());
int num3=Integer.parseInt(Input3.getText());
if(num3==1){ num4=num1+num2 ;}
if(num3==2){ num4=num1-num2 ;}
if(num3==3){ num4=num1*num2 ;}
if(num3==4){ num4=num1/num2 ;}
ShowAnswer.setText(String.valueOf(num4));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询