主题:[讨论]不知道什么问题 请教各位
package tips;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
int number=1000;
JPanel contentPane;
Button button1 = new Button();
JLabel jLabel1 = new JLabel();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField6 = new JTextField();
Button button6 = new Button();
Button button11 = new Button();
Button button12 = new Button();
Button button13 = new Button();
Button button14 = new Button();
JLabel jLabel5 = new JLabel();
TextField textField1 = new TextField();
JLabel jLabel6 = new JLabel();
Panel panel1 = new Panel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
button1.setFont(new java.awt.Font("Dialog", 0, 14));
button1.setLabel("售票点1");
button1.setBounds(new Rectangle(82, 79, 86, 28));
contentPane.setLayout(null);
this.setLocale(java.util.Locale.getDefault());
this.setSize(new Dimension(637, 377));
this.setTitle("模拟多窗口售票程序");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 13));
jLabel1.setText("售票点:");
jLabel1.setBounds(new Rectangle(17, 85, 50, 21));
button2.setFont(new java.awt.Font("Dialog", 0, 14));
button2.setLabel("售票点2");
button2.setBounds(new Rectangle(197, 80, 87, 28));
button3.setFont(new java.awt.Font("Dialog", 0, 14));
button3.setLabel("售票点3");
button3.setBounds(new Rectangle(310, 79, 89, 29));
button4.setFont(new java.awt.Font("Dialog", 0, 14));
button4.setLabel("售票点4");
button4.setBounds(new Rectangle(423, 79, 90, 27));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel2.setText("剩余票数:");
jLabel2.setBounds(new Rectangle(21, 20, 75, 35));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel3.setText("买票:");
jLabel3.setBounds(new Rectangle(22, 137, 36, 27));
jTextField6.setBackground(Color.white);
jTextField6.setSelectionStart(11);
jTextField6.setText("");
jTextField6.setBounds(new Rectangle(118, 64, 147, 22));
button6.setLabel("离开");
button6.setBounds(new Rectangle(262, 327, 56, 25));
button6.addActionListener(new Frame1_button6_actionAdapter(this));
jLabel5.setBackground(Color.pink);
jLabel5.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel5.setForeground(Color.black);
jLabel5.setToolTipText("");
button11.setLabel("购买");
button11.setLocale(java.util.Locale.getDefault());
button11.setBounds(new Rectangle(92, 141, 56, 25));
button11.addActionListener(new Frame1_button11_actionAdapter(this));
button12.setLabel("购买");
button12.setBounds(new Rectangle(211, 140, 58, 25));
button13.setLabel("购买");
button13.setBounds(new Rectangle(323, 141, 58, 25));
button13.addActionListener(new Frame1_button13_actionAdapter(this));
button14.setLabel("购买");
button14.setBounds(new Rectangle(440, 140, 57, 25));
button14.addActionListener(new Frame1_button14_actionAdapter(this));
jLabel5.setText("交易信息:");
jLabel5.setBounds(new Rectangle(22, 67, 85, 22));
textField1.setEditable(false);
textField1.setText("1000");
textField1.setBounds(new Rectangle(118, 22, 145, 22));
jLabel6.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel6.setText("AP0306516 李卓勋 制作");
jLabel6.setBounds(new Rectangle(193, 19, 206, 30));
panel1.setBackground(Color.cyan);
panel1.setBounds(new Rectangle(116, 203, 336, 107));
panel1.setLayout(null);
panel1.add(textField1, null);
panel1.add(jTextField6, null);
panel1.add(jLabel2, null);
panel1.add(jLabel5, null);
contentPane.add(button6, null);
contentPane.add(jLabel6, null);
contentPane.add(button1, null);
contentPane.add(button2, null);
contentPane.add(button3, null);
contentPane.add(button4, null);
contentPane.add(button11, null);
contentPane.add(button12, null);
contentPane.add(jLabel1, null);
contentPane.add(jLabel3, null);
contentPane.add(button13, null);
contentPane.add(button14, null);
contentPane.add(panel1, null);
button12.addActionListener(new Frame1_button12_actionAdapter(this));
}
public class MulThread extends java.lang.Thread
{
StringBuffer buffer;
public MulThread ()
{
buffer =new StringBuffer();
}
public void run ()
{
synchronized (buffer) //使用代码块级关键字synchronized对代码上锁
{
try
{
number=number-1;
}
catch (Exception e) {}
}
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void button11_actionPerformed(ActionEvent e) {
Thread t1=new Thread(new MulThread());
t1.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button12_actionPerformed(ActionEvent e) {
Thread t2=new Thread(new MulThread());
t2.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button13_actionPerformed(ActionEvent e) {
Thread t3=new Thread(new MulThread());
t3.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button14_actionPerformed(ActionEvent e) {
Thread t4=new Thread(new MulThread());
t4.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button15_actionPerformed(ActionEvent e) {
Thread t5=new Thread(new MulThread());
t5.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button6_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button7_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button8_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button9_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button10_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class Frame1_button11_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button11_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button11_actionPerformed(e);
}
}
class Frame1_button12_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button12_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button12_actionPerformed(e);
}
}
class Frame1_button13_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button13_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button13_actionPerformed(e);
}
}
class Frame1_button14_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button14_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button14_actionPerformed(e);
}
}
class Frame1_button6_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button6_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button6_actionPerformed(e);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
int number=1000;
JPanel contentPane;
Button button1 = new Button();
JLabel jLabel1 = new JLabel();
Button button2 = new Button();
Button button3 = new Button();
Button button4 = new Button();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField jTextField6 = new JTextField();
Button button6 = new Button();
Button button11 = new Button();
Button button12 = new Button();
Button button13 = new Button();
Button button14 = new Button();
JLabel jLabel5 = new JLabel();
TextField textField1 = new TextField();
JLabel jLabel6 = new JLabel();
Panel panel1 = new Panel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
button1.setFont(new java.awt.Font("Dialog", 0, 14));
button1.setLabel("售票点1");
button1.setBounds(new Rectangle(82, 79, 86, 28));
contentPane.setLayout(null);
this.setLocale(java.util.Locale.getDefault());
this.setSize(new Dimension(637, 377));
this.setTitle("模拟多窗口售票程序");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 13));
jLabel1.setText("售票点:");
jLabel1.setBounds(new Rectangle(17, 85, 50, 21));
button2.setFont(new java.awt.Font("Dialog", 0, 14));
button2.setLabel("售票点2");
button2.setBounds(new Rectangle(197, 80, 87, 28));
button3.setFont(new java.awt.Font("Dialog", 0, 14));
button3.setLabel("售票点3");
button3.setBounds(new Rectangle(310, 79, 89, 29));
button4.setFont(new java.awt.Font("Dialog", 0, 14));
button4.setLabel("售票点4");
button4.setBounds(new Rectangle(423, 79, 90, 27));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel2.setText("剩余票数:");
jLabel2.setBounds(new Rectangle(21, 20, 75, 35));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel3.setText("买票:");
jLabel3.setBounds(new Rectangle(22, 137, 36, 27));
jTextField6.setBackground(Color.white);
jTextField6.setSelectionStart(11);
jTextField6.setText("");
jTextField6.setBounds(new Rectangle(118, 64, 147, 22));
button6.setLabel("离开");
button6.setBounds(new Rectangle(262, 327, 56, 25));
button6.addActionListener(new Frame1_button6_actionAdapter(this));
jLabel5.setBackground(Color.pink);
jLabel5.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel5.setForeground(Color.black);
jLabel5.setToolTipText("");
button11.setLabel("购买");
button11.setLocale(java.util.Locale.getDefault());
button11.setBounds(new Rectangle(92, 141, 56, 25));
button11.addActionListener(new Frame1_button11_actionAdapter(this));
button12.setLabel("购买");
button12.setBounds(new Rectangle(211, 140, 58, 25));
button13.setLabel("购买");
button13.setBounds(new Rectangle(323, 141, 58, 25));
button13.addActionListener(new Frame1_button13_actionAdapter(this));
button14.setLabel("购买");
button14.setBounds(new Rectangle(440, 140, 57, 25));
button14.addActionListener(new Frame1_button14_actionAdapter(this));
jLabel5.setText("交易信息:");
jLabel5.setBounds(new Rectangle(22, 67, 85, 22));
textField1.setEditable(false);
textField1.setText("1000");
textField1.setBounds(new Rectangle(118, 22, 145, 22));
jLabel6.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel6.setText("AP0306516 李卓勋 制作");
jLabel6.setBounds(new Rectangle(193, 19, 206, 30));
panel1.setBackground(Color.cyan);
panel1.setBounds(new Rectangle(116, 203, 336, 107));
panel1.setLayout(null);
panel1.add(textField1, null);
panel1.add(jTextField6, null);
panel1.add(jLabel2, null);
panel1.add(jLabel5, null);
contentPane.add(button6, null);
contentPane.add(jLabel6, null);
contentPane.add(button1, null);
contentPane.add(button2, null);
contentPane.add(button3, null);
contentPane.add(button4, null);
contentPane.add(button11, null);
contentPane.add(button12, null);
contentPane.add(jLabel1, null);
contentPane.add(jLabel3, null);
contentPane.add(button13, null);
contentPane.add(button14, null);
contentPane.add(panel1, null);
button12.addActionListener(new Frame1_button12_actionAdapter(this));
}
public class MulThread extends java.lang.Thread
{
StringBuffer buffer;
public MulThread ()
{
buffer =new StringBuffer();
}
public void run ()
{
synchronized (buffer) //使用代码块级关键字synchronized对代码上锁
{
try
{
number=number-1;
}
catch (Exception e) {}
}
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void button11_actionPerformed(ActionEvent e) {
Thread t1=new Thread(new MulThread());
t1.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button12_actionPerformed(ActionEvent e) {
Thread t2=new Thread(new MulThread());
t2.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button13_actionPerformed(ActionEvent e) {
Thread t3=new Thread(new MulThread());
t3.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button14_actionPerformed(ActionEvent e) {
Thread t4=new Thread(new MulThread());
t4.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button15_actionPerformed(ActionEvent e) {
Thread t5=new Thread(new MulThread());
t5.start();
if(number<=0)
jTextField6.setText("票已售完!");
else
jTextField6.setText("成功交易");
textField1.setText(""+number+"");
}
void button6_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button7_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button8_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button9_actionPerformed(ActionEvent e) {
System.exit(0);
}
void button10_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
class Frame1_button11_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button11_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button11_actionPerformed(e);
}
}
class Frame1_button12_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button12_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button12_actionPerformed(e);
}
}
class Frame1_button13_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button13_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button13_actionPerformed(e);
}
}
class Frame1_button14_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button14_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button14_actionPerformed(e);
}
}
class Frame1_button6_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_button6_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button6_actionPerformed(e);
}
}