| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2010 人关注过本帖
标题:[原创z自己做的小计算器
只看楼主 加入收藏
wuzhong
Rank: 1
等 级:新手上路
帖 子:233
专家分:0
注 册:2006-10-23
收藏
得分:0 
大家在一起学习的气氛相当的好.团队精神就是这样的.呵呵.

2007-01-19 13:00
wuzhong
Rank: 1
等 级:新手上路
帖 子:233
专家分:0
注 册:2006-10-23
收藏
得分:0 
还是有错误,x-y>0;这个有错.

2007-01-19 13:05
开心一科
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-10-5
收藏
得分:0 

仿楼主的模子,克隆了一个,呵呵!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class KaoShiSystemTest extends JFrame
{
JLabel welcome,builder,contact;
JButton jenter,jcanceal;
public KaoShiSystemTest()
{
Container con = getContentPane();
con.setBackground(Color.blue);
con.setLayout(new BorderLayout());
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();

welcome = new JLabel("欢迎光临哈哈考试系统");
welcome.setForeground(Color.blue);
// welcome.setOpaque(true);
welcome.setFont(new Font("宋体",Font.BOLD,24));
builder = new JLabel("制作单位:哈哈工作室",JLabel.CENTER);
builder.setFont(new Font("宋体",Font.PLAIN,18));
contact = new JLabel("联系人:哈哈一族 QQ:77129661",JLabel.CENTER);
contact.setFont(new Font("宋体",Font.PLAIN,18));
JButton jenter = new JButton("确定");
jenter.setOpaque(true);
JButton jcanceal = new JButton("取消");
jcanceal.setOpaque(true);

jp1.add(welcome);
jp2.setLayout(new GridLayout(2,1));
jp2.add(builder);
jp2.add(contact);
jenter.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame jframe = new JFrame();
Dialog1 dia1 = new Dialog1(jframe,"哈哈考试系统");
//dia1.setVisible(true);
}});
jp3.add(jenter);
jcanceal.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
jp3.add(jcanceal);

jp1.setOpaque(true);
jp2.setOpaque(true);
jp3.setOpaque(true);

jp1.setBackground(Color.pink);
jp2.setBackground(Color.pink);
jp3.setBackground(Color.pink);

con.add(jp1,BorderLayout.NORTH);
con.add(jp2,BorderLayout.CENTER);
con.add(jp3,BorderLayout.SOUTH);

setSize(400,300);
this.setVisible(true);
setBackground(Color.blue);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new KaoShiSystemTest();

}

}

class Dialog1 extends JDialog implements ActionListener
{
JFrame frame;
String str;
JLabel jla1,jla2,jla3,jla4,jla5;
JTextField jtext;
JComboBox jcom;
JButton jb1, jb2, jb3, jb4;
String [] data = {"+","-","*","/"};
Random random = new Random();
Dialog1(JFrame jf , String s)
{
frame = jf;
str = s;
init();
}
public void init()
{
setTitle(str);
// setBackground(Color.blue);
//setVisible(true);
Container container = frame.getContentPane();
container.setLayout(new BorderLayout());
frame.setBounds(new Rectangle(50,50,400,100));
JPanel pa1 = new JPanel();
JPanel pa2 = new JPanel();
JPanel pa3 = new JPanel();

pa1.setBackground(Color.pink);
pa2.setBackground(Color.pink);
pa3.setBackground(Color.pink);


jla1 = new JLabel(Integer.toString(random.nextInt(50)),JLabel.CENTER);
jla2= new JLabel(Integer.toString(random.nextInt(50)),JLabel.CENTER);
jla3 = new JLabel("=",JLabel.CENTER);
jla4 = new JLabel();
jla5 = new JLabel();
jcom = new JComboBox(data);
jtext = new JTextField("");
jb1 = new JButton("判断");
jb1.addActionListener(this);
jb2 = new JButton("下一题");
jb2.addActionListener(this);
jb3 = new JButton("帮助");
jb3.addActionListener(this);
jb4 = new JButton("退出");
jb4.addActionListener(this);

pa3.add(jla5);
container.add(pa3,BorderLayout.NORTH);
pa1.setLayout(new GridLayout(1,6));
pa1.add(jla1);
// pa1.add(jscroll);
pa1.add(jcom);
pa1.add(jla2);
pa1.add(jla3);
pa1.add(jtext);
pa1.add(jb1);
container.add(pa1,BorderLayout.CENTER);

pa2.add(jb2);
pa2.add(jb3);
pa2.add(jb4);
pa2.add(jla4);
container.add(pa2,BorderLayout.SOUTH);

frame.show();
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("判断"))
{
if(jtext.getText().toString().equals(""))
JOptionPane.showMessageDialog(null,"你还没有写结果哦!");
else
{
int jieguo = Integer.parseInt(jtext.getText());
int num1 = Integer.parseInt(jla1.getText());
int num2 = Integer.parseInt(jla2.getText());
//String fu = (list.getModel().getElementAt(random.nextInt(4))).toString();
String fu = jcom.getSelectedItem().toString();
int jie;
if(fu.equals("*"))
jie = num1 * num2;
else if (fu.equals("-"))
jie = num1 - num2;
else if (fu.equals("+"))
jie = num1 + num2;
else
jie = num1 / num2;
if(jieguo == jie)
jla4.setText("你答题正确");
else
jla4.setText("你答题错误");
}
}

else if (e.getActionCommand().equals("下一题"))
{
jla1.setText(Integer.toString(random.nextInt(50)));
jla2.setText(Integer.toString(random.nextInt(50)));
jcom.setSelectedIndex(random.nextInt(4));
jtext.setText("");
jla4.setText("");
}
else if (e.getActionCommand().equals("帮助"))
{
JOptionPane.showMessageDialog(Dialog1.this,"简单考试系统演示,^_^");
}
else if (e.getActionCommand().equals("退出"))
{
System.exit(0);
}
}

}


2007-01-19 15:22
yudiao123
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2007-1-19
收藏
得分:0 
不懂!!

2007-01-19 19:24
wuzhong
Rank: 1
等 级:新手上路
帖 子:233
专家分:0
注 册:2006-10-23
收藏
得分:0 
开心一科,不错.

2007-01-19 22:31
快速回复:[原创z自己做的小计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022757 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved