首页 > 代码库 > 星期四、星期五、星期一—用GUI做一个简易的交易系统

星期四、星期五、星期一—用GUI做一个简易的交易系统

1、登录界面

package org.eclipse.wb.swing;
//登录界面

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Label;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JPasswordField;
import java.awt.Color;

                                 //导入所需要的包
public class Suibian3 extends JFrame {
	static Suibian3 frame = new Suibian3();//建一个继承JFrame的类
	public static void main(String[] args) {
		new Suibian1();                         //关联到Suibian1这个类
		new Suibian2();	
		new Jiaoyi();
		new Suibian4();
		new Suibian5();
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {                 //构建一个run函数
				try {
			
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	public Suibian3() {                                 //建立框体
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("登录界面");
		setBounds(100, 100, 450, 350);
		contentPane = new JPanel();
		contentPane.setForeground(new Color(95, 158, 160));
		contentPane.setBackground(new Color(0, 206, 209));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		textField = new JTextField();           //输密码的文本框
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("\u767B\u5F55");  //添加一个登录按钮
		btnNewButton.setBackground(new Color(127, 255, 212));
		btnNewButton.setForeground(new Color(0, 0, 0));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String a = "123654";
				String b = "987456";
				String c = textField.getText();
				String d = passwordField.getText();
				if(a.equals(c)&&b.equals(d)){                 //用if条件判断账户和密码输入是否正确
					new Jiaoyi().setVisible(true);
				}else{
				JOptionPane.showMessageDialog(null, "密码或账号输入错误", "alert", JOptionPane.ERROR_MESSAGE);
				}
				frame.setVisible(false);	
			}
		});		
		
		JButton button = new JButton("\u6CE8\u518C");
		button.setBackground(new Color(127, 255, 212));
		button.setForeground(new Color(0, 0, 0));
		
		JLabel lblNewLabel = new JLabel("\u8D26\u53F7");
		
		JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801");
		
		JRadioButton radioButton_1 = new JRadioButton("\u5FD8\u8BB0\u5BC6\u7801");
		
		passwordField = new JPasswordField();
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(24)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel)
						.addComponent(lblNewLabel_1))
					.addGap(27)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(25)
							.addComponent(btnNewButton)
							.addGap(37)
							.addComponent(button)
							.addContainerGap(173, Short.MAX_VALUE))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(passwordField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
								.addComponent(textField, GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
							.addGap(107))))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(218)
					.addComponent(radioButton_1, 0, 0, Short.MAX_VALUE)
					.addGap(124))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(56)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel))
					.addGap(30)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE))
					.addGap(40)
					.addComponent(radioButton_1)
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
					.addGap(35))
		);
		contentPane.setLayout(gl_contentPane);
	}
}  

2、主界面

package org.eclipse.wb.swing;
//主界面

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.Font;

public class Jiaoyi extends JFrame {

	private JPanel contentPane;
	private JTextArea textArea;

	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		new Suibian1();
//		new Suibian2();	
//		new Suibian3();
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					Jiaoyi frame = new Jiaoyi();
//					frame.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
//	}

	/**
	 * Create the frame.
	 */
	public Jiaoyi() {                               //登录后的界面窗口
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("主界面");
		setBounds(100, 100, 800, 500);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.textHighlight);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JButton btnNewButton = new JButton("商品信息管理");  //添加购物车按钮
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
             new Suibian1().setVisible(true);                       //关联到对应的窗口
			}
		});	
		
		btnNewButton.setBackground(Color.CYAN);
		
		JButton button = new JButton("\u5546\u54C1\u76EE\u5F55"); //商品信息窗口
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
             new Suibian2().setVisible(true);                  //关联到对应的窗口
			}
		});	
		button.setBackground(Color.CYAN);
		
		JButton button_1 = new JButton("\u8D2D\u4E70\u4FE1\u606F");//购买信息按钮
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
             new Suibian4().setVisible(true);                  //关联到对应的窗口
			}
		});	                                                           
		button_1.setBackground(Color.CYAN);
		
		JButton button_2 = new JButton("\u8D2D\u4E70\u5386\u53F2");   //购买历史按钮
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				                    
				try {                  
					FileInputStream	in = new FileInputStream("D:\\workspace\\购买.txt");   //利用字节的输入流把所用的文本在文本域中读出来
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"清除历史记录", "alert", JOptionPane.ERROR_MESSAGE);
		//		File oo=new File("D:\\workspace\\购买.txt");
				FileOutputStream goumai = null;
				try {
					goumai = new FileOutputStream("D:\\workspace\\购买.txt");
					String qwe="";
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}		
			}
			
		});	                                                             
		button_2.setBackground(Color.CYAN);
		
		JButton btnNewButton_1 = new JButton("\u4F1A\u5458\u4FE1\u606F"); //会员管理按钮
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                               //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\会员管理.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"\u7528\u6237\u7BA1\u7406"); //用户管理按钮
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                            //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\用户信息.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"Monospaced", Font.PLAIN, 14));
		textArea.setForeground(SystemColor.desktop);
		textArea.setLineWrap(true);                   //对文本域中的文字进行自动换行
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(25)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE))
						.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 583, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(button_2, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
						.addGroup(Alignment.TRAILING, gl_contentPane.createParallelGroup(Alignment.TRAILING)
							.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
							.addComponent(button, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE)
							.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE))))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(32, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(button, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(textArea, GroupLayout.PREFERRED_SIZE, 352, GroupLayout.PREFERRED_SIZE)
							.addGap(18)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(button_3, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
								.addComponent(btnNewButton_1, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap())
		);
		contentPane.setLayout(gl_contentPane);
	}
}  

3、购买信息管理

package com.chinasoft.gui.PM;
//商品信息管理
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JTextArea;

import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;

public class Suibian1 extends JFrame {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	public Suibian1() {                                 //建立一个库存管理的窗口
		getContentPane().setBackground(new Color(143, 188, 143));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("商品信息管理");
		setBounds(100, 100, 450, 300);
		
		textField = new JTextField();
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("\u5546\u54C1\u540D");
		
		JLabel label = new JLabel("\u5546\u54C1\u4EF7\u683C");
		
		JLabel label_1 = new JLabel("\u5546\u54C1\u5E93\u5B58");
		
		JButton button = new JButton("\u6DFB\u52A0\u5546\u54C1");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {  //添加商品
				
		for(int i = 1;i<=10;i++){
			if(Suibian4.af[i][0] == null){
				Suibian4.af[i][0]= textField_2.getText();     //商品名
				Suibian4.af[i][1]= textField_3.getText();  //商品种类
				Suibian4.af[i][2] =textField_1.getText();     //商品价格
				Suibian4.af[i][3] =textField.getText();     //商品库存
             break;
			}
		}
			}
		});
		button.setBackground(Color.CYAN);
		
		JButton button_1 = new JButton("\u5546\u54C1\u67E5\u8BE2");   //查询
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 1;i<=10;i++){
					if(Suibian4.af[i][0].equals(textField_2.getText()) ){
						textField_3.setText((String) Suibian4.af[i][1]); //商品种类
						textField_1.setText((String) Suibian4.af[i][2]) ;     //商品价格
						textField.setText((String) Suibian4.af[i][3])  ;     //商品库存
		            	   
					}
					 break;	
					}
			}
		});
		button_1.setBackground(Color.CYAN);
		
		JButton button_2 = new JButton("\u5546\u54C1\u4FEE\u6539");  //修改
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 1;i<=10;i++){
					if(Suibian4.af[i][0].equals(textField_2.getText()) ){
						Suibian4.af[i][1]= textField_3.getText();  //商品种类
						Suibian4.af[i][2] =textField_1.getText();     //商品价格
						Suibian4.af[i][3] =textField.getText();     //商品库存
		            	   
					}
					 break;	
					}
			}
		});
		button_2.setBackground(Color.CYAN);
		
		JButton button_3 = new JButton("\u5546\u54C1\u5220\u9664");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 1;i<=10;i++){
					if(Suibian4.af[i][0].equals(textField_2.getText()) ){
						Suibian4.af[i][0]= null;
						Suibian4.af[i][1]= null;  //商品种类
						Suibian4.af[i][2] =null;     //商品价格
						Suibian4.af[i][3] =null;     //商品库存      	   
					}
					 break;	
					}	
			}
		});
		button_3.setBackground(Color.CYAN);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		
		JLabel label_2 = new JLabel("\u5546\u54C1\u79CD\u7C7B");
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(73)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
					.addGap(47)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(108, Short.MAX_VALUE))
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel)
								.addComponent(label)
								.addComponent(label_1))
							.addGap(16))
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)))
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 290, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 290, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 290, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 290, GroupLayout.PREFERRED_SIZE))
					.addGap(71))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(34)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel))
					.addGap(10)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addComponent(label))
					.addGap(10)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_1))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_2))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE))
					.addContainerGap())
		);
		getContentPane().setLayout(groupLayout);
	}
}  

4、购买信息

package com.chinasoft.gui.PM;
//购买信息
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;

public class Suibian4 extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private JTable table_1;
	private JTable table_2;
	private JButton button_1;
	private JButton button_2;
	private JButton button_3;
	private JButton button_4;
	private JButton button_5;
	private JButton button_6;
	private JButton button_7;
	private JButton button_8;
	static Object[][] af={
	{"\u7269\u54C1\u540D\u79F0", "\u7269\u54C1\u79CD\u7C7B", "\u7269\u54C1\u4EF7\u683C", "\u7269\u54C1\u6570\u91CF", "\u7269\u54C1\u603B\u4EF7"},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
	{null,null,null,null},
};
	private JButton btnNewButton;
	public Suibian4() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("购买信息");
		setBounds(100, 100, 750, 530);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(222, 184, 135));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		table = new JTable();		
		table_1 = new JTable();		
		table_2 = new JTable();
		table_2.setRowHeight(38);
		table_2.setFont(new Font("宋体", Font.PLAIN, 12));
		table_2.setBorder(new LineBorder(new Color(0, 0, 0)));
		table_2.setModel(new DefaultTableModel(
			af,
			new String[] {
				"\u7269\u54C1\u540D\u79F0", "\u7269\u54C1\u79CD\u7C7B", "\u7269\u54C1\u4EF7\u683C", "\u7269\u54C1\u5E93\u5B58"
			}
		));
		table_2.getColumnModel().getColumn(0).setMinWidth(25);
		table_2.getColumnModel().getColumn(2).setMinWidth(25);
			
		JButton button = new JButton("\u8D2D\u4E70");
		button.setBackground(new Color(175, 238, 238));
		button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
				File file = new File("D:\\workspace\\购买.txt");
				try {
					FileOutputStream goumai=new FileOutputStream("D:\\workspace\\购买.txt",true);
					String qwe=(String) table_2.getValueAt(1, 0)+"  "+table_2.getValueAt(1, 1)
				+"  "+table_2.getValueAt(1, 2)+"  "+table_2.getValueAt(1, 3)+System.getProperty("line.separator");
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		
		button_1 = new JButton("\u8D2D\u4E70");
		button_1.setBackground(new Color(175, 238, 238));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				File file = new File("D:\\workspace\\购买.txt");
				try {
					FileOutputStream goumai=new FileOutputStream("D:\\workspace\\购买.txt",true);
					String qwe=(String) table_2.getValueAt(2, 0)+"  "+table_2.getValueAt(2, 1)
				+"  "+table_2.getValueAt(2, 2)+"  "+table_2.getValueAt(2, 3)+System.getProperty("line.separator");
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		
		button_2 = new JButton("\u8D2D\u4E70");
		button_2.setBackground(new Color(175, 238, 238));
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				File file = new File("D:\\workspace\\购买.txt");
				try {
					FileOutputStream goumai=new FileOutputStream("D:\\workspace\\购买.txt",true);
					String qwe=(String) table_2.getValueAt(3, 0)+"  "+table_2.getValueAt(3, 1)
				+"  "+table_2.getValueAt(3, 2)+"  "+table_2.getValueAt(3, 3)+System.getProperty("line.separator");
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		
		button_3 = new JButton("\u8D2D\u4E70");
		button_3.setBackground(new Color(175, 238, 238));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				File file = new File("D:\\workspace\\购买.txt");
				try {
					FileOutputStream goumai=new FileOutputStream("D:\\workspace\\购买.txt",true);
					String qwe=(String) table_2.getValueAt(4, 0)+"  "+table_2.getValueAt(4, 1)
				+"  "+table_2.getValueAt(4, 2)+"  "+table_2.getValueAt(4, 3)+System.getProperty("line.separator");
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		
		button_4 = new JButton("\u8D2D\u4E70");
		button_4.setBackground(new Color(175, 238, 238));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				File file = new File("D:\\workspace\\购买.txt");
				try {
					FileOutputStream goumai=new FileOutputStream("D:\\workspace\\购买.txt",true);
					String qwe=(String) table_2.getValueAt(5, 0)+"  "+table_2.getValueAt(5, 1)
				+"  "+table_2.getValueAt(5, 2)+"  "+table_2.getValueAt(5, 3)+System.getProperty("line.separator");
//					 String str4 =System.getProperty("line.separator");//输出换行
//					byte[] f2 = str4.getBytes();
					byte[]ab = qwe.getBytes();
					goumai.write(ab);
					
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} 				
			}
		});
		button_5 = new JButton("\u8D2D\u4E70");
		button_5.setBackground(new Color(175, 238, 238));
		button_6 = new JButton("\u8D2D\u4E70");
		button_6.setBackground(new Color(175, 238, 238));
		
		button_7 = new JButton("\u8D2D\u4E70");
		button_7.setBackground(new Color(175, 238, 238));
		
		button_8 = new JButton("\u8D2D\u4E70");
		button_8.setBackground(new Color(175, 238, 238));
		
		btnNewButton = new JButton("\u4ED8\u6B3E");
		btnNewButton.setBackground(new Color(175, 238, 238));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				 new Suibian5().setVisible(true);
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(30)
							.addComponent(table_2, GroupLayout.PREFERRED_SIZE, 617, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(button_8, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_7, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_6, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_5, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_4, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addComponent(button, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(1)
							.addComponent(table, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(293)
							.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(1)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(table, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(table_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(45)
							.addComponent(button)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_1)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_2)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_3)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_4)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_5)
							.addGap(10)
							.addComponent(button_6)
							.addGap(10)
							.addComponent(button_7)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_8)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(8))
		);
		contentPane.setLayout(gl_contentPane);
	}
}  

5、商品目录

package com.chinasoft.gui.PM;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextArea;

//import org.eclipse.wb.swing.FocusTraversalOnArray;

import java.awt.Component;
import java.awt.Font;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
//商品目录
public class Suibian2 extends JFrame {
	private JPanel contentPane;
	private JLabel lblMsg;
	private JTextArea textArea;
	public Suibian2() {                              //建立商品信息的窗口
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 700, 500);
		this.setTitle("商品种类");
		contentPane = new JPanel();
		contentPane.setToolTipText("");
		contentPane.setBackground(new Color(0, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		lblMsg = new JLabel("");
		
		final JComboBox comboBox = new JComboBox();            //图书类的下拉列表
		comboBox.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
	
			}
		});
		comboBox.setFont(new Font("宋体", Font.PLAIN, 15));
		comboBox.setToolTipText("图书类");
		comboBox.addItem("童书");
	    comboBox.addItem("文学");
	//	comboBox.setModel(new DefaultComboBoxModel( new String[] {"童书", "文学", "\u6559\u80B2", "\u4EBA\u6587\u793E\u79D1", "\u7ECF\u8425", "\u827A\u672F", "\u8BA1\u7B97\u673A", "\u79D1\u6280", "\u751F\u6D3B"}));
	    comboBox.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {		
			String b = "童书";
		    String c = "文学";
    //    String [] a = new String[] {"童书", "文学", "\u6559\u80B2", "\u4EBA\u6587\u793E\u79D1", "\u7ECF\u8425", "\u827A\u672F", "\u8BA1\u7B97\u673A", "\u79D1\u6280", "\u751F\u6D3B"};
		if(b.equals(comboBox.getItemAt(2))){
		
				FileInputStream in;                    //利用字节的输入流把所用的文本在文本域中读出来
				try {                  
					in = new FileInputStream("D:\\workspace\\童书.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"D:\\workspace\\文学.txt");
					DataInputStream c1=new DataInputStream(a);
					 byte[] d=new byte[c1.available()];
					 c1.read(d);
					 String s=new String(d);
					 textArea.setText(s);		        //在文本域中读出所需的文件
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}	
	  }
		}
		});
		
		JComboBox comboBox_1 = new JComboBox();          //电器类的下拉列表
		comboBox_1.setToolTipText("电器类");
		comboBox_1.setFont(new Font("宋体", Font.PLAIN, 15));
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"\u7A7A\u8C03", "\u51B0\u7BB1", "\u6D17\u8863\u673A", "\u7535\u89C6", "\u70ED\u6C34\u5668", "\u7535\u98CE\u6247", "\u5438\u5C18\u5668"}));
		comboBox_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                       //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\空调.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"服装类");
		comboBox_2.setFont(new Font("宋体", Font.PLAIN, 15));
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"\u77ED\u8896T\u6064", "\u957F\u8896T\u6064", "\u4F11\u95F2\u88E4", "\u5939\u514B", "\u886C\u886B", "\u725B\u4ED4\u88E4", "\u77ED\u88E4", "\u536B\u8863", "\u897F\u88C5"}));
		comboBox_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                        //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\短袖T恤.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"母婴类");
		comboBox_3.setFont(new Font("宋体", Font.PLAIN, 15));
		comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"\u5976\u7C89", "\u5C3F\u88E4\u6E7F\u5DFE", "\u6D17\u62A4\u7528\u54C1", "\u7AE5\u8F66\u7AE5\u5E8A", "\u5976\u74F6", "\u5976\u5634", "\u5C3F\u4E0D\u6E7F"}));
		comboBox_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                   //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\奶粉.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"食品类");
		comboBox_4.setFont(new Font("宋体", Font.PLAIN, 15));
		comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"\u5DE7\u514B\u529B", "\u575A\u679C", "\u8336", "\u5496\u5561", "\u996E\u6599", "\u5976\u8336", "\u725B\u5976", "\u8FA3\u6761", "\u7CD6\u679C"}));
		comboBox_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileInputStream in;                    //利用字节的输入流把所用的文本在文本域中读出来
				try {
					in = new FileInputStream("D:\\workspace\\巧克力.txt");
					DataInputStream data=http://www.mamicode.com/new DataInputStream(in);"\u56FE\u4E66\u7C7B");
		
		JLabel label = new JLabel("\u7535\u5668\u7C7B");
		
		JLabel label_1 = new JLabel("\u670D\u88C5\u7C7B");
		
		JLabel label_2 = new JLabel("\u6BCD\u5A74\u7C7B");
		
		JLabel label_3 = new JLabel("\u98DF\u54C1\u7C7B");
	//	 textArea.setLineWrap(true);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(label_3)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(comboBox_4, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(label_2)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(comboBox_3, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))
						.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
							.addComponent(label_1)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(label)
							.addGap(43)
							.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(textArea, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(textArea, GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(19)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
								.addComponent(label, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
							.addGap(42)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(comboBox_2, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
								.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
							.addGap(43)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(comboBox_3, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
								.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
							.addGap(41)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(comboBox_4, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
								.addComponent(label_3, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap())
		);
		contentPane.setLayout(gl_contentPane);
	//	contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{comboBox}));
	}
}  

6、结账系统

package com.chinasoft.gui.PM;
//结算
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class Suibian5 extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;

	public Suibian5() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("结算");
		setBounds(100, 100, 416, 523);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 240, 245));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		textField = new JTextField();
		for(int i = 1;i<=10;i++){
			if(Suibian4.af[i][0] != null){
				textField.setText((String) Suibian4.af[i][2]+"+"+(String) Suibian4.af[i+1][2]
			+"+"+(String) Suibian4.af[i+2][2]+"+"+(String) Suibian4.af[i+3][2]);	     //商品价格		   
             break;
			}
		}
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		for(int j = 1;j<=10;j++){
			if(Suibian4.af[j][0] != null){
				textField_1.setText((String) Suibian4.af[j][3]+"+"+(String) Suibian4.af[j+1][3]
			+"+"+(String) Suibian4.af[j+2][3]+"+"+(String) Suibian4.af[j+3][3]);	     //商品数量		   
             break;
			}
		}
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("\u4EF7\u683C");
		
		JLabel lblNewLabel_1 = new JLabel("\u6570\u91CF");
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		
		JButton btnNewButton = new JButton("\u627E\u96F6");
		btnNewButton.setBackground(new Color(230, 230, 250));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		String str = textField_2.getText();
		String str1 = textField_3.getText();		
		int c = Integer.parseInt(str);
		int d = Integer.parseInt(str1);
		int div = c - d;
		textField_4.setText(Integer.toString(div));
			}
		});	
		JButton button = new JButton("\u7ED3\u7B97");
		button.setBackground(new Color(230, 230, 250));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str = textField_3.getText();
				byte []b1 = new byte[str.length()];
				b1 = str.getBytes();
			    int endIndex = str.length();
			    
				   for(int i =0;i <str.length();i++ ){	
					   if(b1[i] == ‘+‘){			
						//获取第一个数字
						int index11 = str.indexOf("+");
						String str1 = str.substring(0, index11);					
						int a = Integer.parseInt(str1);
						//获取第二个数字
						String str2 = str.substring(index11+1, endIndex);
						int b = Integer.parseInt(str2);
						//加法计算
						int sum = a + b;	
						
						//输出结果
						textField_3.setText(Integer.toString(sum));
					   }else
					   if(b1[i] == ‘-‘){
						int index33 = str.indexOf("-");
						String str3 = str.substring(0, index33);					
						int c = Integer.parseInt(str3);
						
						String str4 = str.substring(index33+1, endIndex);
						int d = Integer.parseInt(str4);
						
						int div = c - d;	
					
						
						textField_3.setText(Integer.toString(div));
				
					   }else
					   if(b1[i] == ‘*‘){
						int index44 = str.indexOf("*");
						String str11 = str.substring(0, index44);					
						int c1 = Integer.parseInt(str11);	
						String str12 = str.substring(index44+1, endIndex);
						int d1 = Integer.parseInt(str12);				
						int cheng = c1 * d1;	
						textField_3.setText(Integer.toString(cheng));

					   }else
						if(b1[i] == ‘/‘){
						int index5 = str.indexOf("/");
						String str13 = str.substring(0, index5);					
						int c2 = Integer.parseInt(str13);
						String str14 = str.substring(index5+1, endIndex);
						int d2 = Integer.parseInt(str14);				
						int chu = c2 / d2;				
						textField_3.setText(Integer.toString(chu));
					   }
					}	   
				}
			});		
		JButton button_1 = new JButton("\u6E05\u96F6");
		button_1.setBackground(new Color(230, 230, 250));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField_3.setText("");
				textField_4.setText("");
		}
	});
		JButton button_2 = new JButton("0");
		button_2.setBackground(new Color(230, 230, 250));
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "0");
			}
		});
		JButton button_3 = new JButton("7");
		button_3.setBackground(new Color(230, 230, 250));
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "7");
			}
		});
		JButton button_4 = new JButton("8");
		button_4.setBackground(new Color(230, 230, 250));
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "8");
			}
		});
		JButton button_5 = new JButton("9");
		button_5.setBackground(new Color(230, 230, 250));
		button_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "9");
			}
		});
		JButton button_6 = new JButton("*");
		button_6.setBackground(new Color(230, 230, 250));
		button_6.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "*");
			}
		});
		
		JButton button_7 = new JButton("4");
		button_7.setBackground(new Color(230, 230, 250));
		button_7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "4");
			}
		});
		
		JButton button_8 = new JButton("5");
		button_8.setBackground(new Color(230, 230, 250));
		button_8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "5");
			}
		});
		
		JButton button_9 = new JButton("6");
		button_9.setBackground(new Color(230, 230, 250));
		button_9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "6");
			}
		});
		
		JButton button_10 = new JButton("-");
		button_10.setBackground(new Color(230, 230, 250));
		button_10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "-");
			}
		});
		
		JButton button_11 = new JButton("1");
		button_11.setBackground(new Color(230, 230, 250));
		button_11.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "1");
			}
		});
		
		JButton button_12 = new JButton("2");
		button_12.setBackground(new Color(230, 230, 250));
		button_12.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "2");
			}
		});
		
		JButton button_13 = new JButton("3");
		button_13.setBackground(new Color(230, 230, 250));
		button_13.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "3");
			}
		});
		
		JButton button_14 = new JButton("+");
		button_14.setBackground(new Color(230, 230, 250));
		button_14.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		textField_3.setText(textField_3.getText() + "+");
			}
		});
		
		JLabel label = new JLabel("\u5B9E\u4ED8");
		
		JLabel label_1 = new JLabel("\u5E94\u4ED8");
		
		JLabel label_2 = new JLabel("\u627E\u96F6");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(8)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(label, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblNewLabel))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
								.addComponent(textField_2)
								.addComponent(textField, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
							.addPreferredGap(ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
									.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)))
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
								.addComponent(textField_3, Alignment.LEADING)
								.addComponent(textField_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(button_11, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_12, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(button_13, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_14, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(button_7, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_8, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(button_9, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_10, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_4, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(button_5, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_6, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE))
								.addComponent(textField_4))))
					.addGap(41))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel)
						.addComponent(lblNewLabel_1)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
						.addComponent(label)
						.addComponent(label_1))
					.addGap(43)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
						.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
							.addComponent(button_3, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
							.addComponent(button_4, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
						.addComponent(button_5, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_6, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(button_7, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_8, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_9, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
						.addComponent(button_10, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
							.addComponent(button_11, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
							.addComponent(button_12, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
							.addComponent(button_13, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
						.addComponent(button_14, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(76, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
}

星期四、星期五、星期一—用GUI做一个简易的交易系统