求java的GUI小程序(2个数的和)
6个回答
展开全部
import javax.swing.*;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
这是以前一个程序临时修改的,你看符合要求吗,不符合再给你写一个,没出界面的话最小化然后回复就刷新出啦了
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
这是以前一个程序临时修改的,你看符合要求吗,不符合再给你写一个,没出界面的话最小化然后回复就刷新出啦了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import javax.swing.*;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
//这是临时修改的,你看下,不符合再说
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
//这是临时修改的,你看下,不符合再说
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import javax.swing.*;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Calculator
{
JFrame f;
JTextField op1,op2,op,op3;
JPanel p1,p2;
public void display()
{
f = new JFrame("加法计算器");
f.setSize(280,300); f.setLocation(320,240);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.setVisible(true);
op1= new JTextField("0",4);
op2= new JTextField("0",4);
op3= new JTextField("0",4);
p1=new JPanel();
p1.add(op1);
p1.add(new JLabel("+"));
p1.add(op2);
p1.add(new JLabel("="));
p1.add(op3);
f.add(p1);
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
op3.setText(""+(Integer.parseInt(op1.getText())+Integer.parseInt(op2.getText())));
}
});
button.setText("提交");
p1.add(button);
p2=new JPanel();
f.add(p2);
f.addWindowListener(new WinClose());
}
public static void main(String arg[])
{
(new Calculator()).display();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){ } ; //窗口打开时调用
public void windowIconified(WindowEvent e){ }; //窗口图标化时调用
public void windowDeiconified(WindowEvent e){ }; //窗口非图标化时调用
public void windowClosed(WindowEvent e){ }; //窗口关闭时调用
public void windowActivated(WindowEvent e){ }; //窗口激活时调用
public void windowDeactivated(WindowEvent e){ }; //窗口非激活时调用
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以买JAVA助手上面有
追问
求源代码啊 输出框大小也设置下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Swt~~你值得拥有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询