The Artima Developer Community
Sponsored Link

Java Answers Forum
JButton Problem

1 reply on 1 page. Most recent reply: Mar 27, 2009 11:51 AM by vince vinci

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
vince vinci

Posts: 2
Nickname: opera33
Registered: Mar, 2009

JButton Problem Posted: Mar 27, 2009 6:35 AM
Reply to this message Reply
Advertisement

package Panel;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import java.text.*;

public class RestaurantPlan extends JPanel implements ActionListener {

PreparedStatement pstmtSubmit;

static String[] seat = {"1","2","3","4","5","6","7","8","9","10"};

JLabel jlbCashier = new JLabel("Cashier");
JLabel jlbRestroom = new JLabel("Female");
JLabel jlbRestroom2 = new JLabel("Male");
JLabel jlbMainDoor = new JLabel("Main Door");
JLabel jlbTitle = new JLabel("Reservation Details");
JLabel jlbDate = new JLabel("Date: ");
JLabel jlbTime = new JLabel("Time: ");
JLabel jlbSeat = new JLabel("Seat: ");
JLabel jlbName = new JLabel("Name: ");
JLabel jlbID = new JLabel("Cust. ID: ");

JLabel jlbBigTable = new JLabel("Table for 10");
JLabel jlbMedTable = new JLabel("Table for 4");
JLabel jlbSmallTable = new JLabel("Table for 2");
JLabel jlbNA = new JLabel("Not Available");

JLabel jlbStar = new JLabel("*");
JLabel jlbNote = new JLabel("* = required field");
JLabel jlbBtm = new JLabel("For reservation more than 3 tables or more than 20 peoples, please call for staff or call 03-41450123");

static JTextField jtfDate = new JTextField();
static JTextField jtfTime = new JTextField();
static JTextField jtfName = new JTextField();
static JTextField jtfID = new JTextField();

JSeparator jsBtm = new JSeparator(JSeparator.HORIZONTAL);
JSeparator jsSouth = new JSeparator(JSeparator.HORIZONTAL);
JSeparator jsEast = new JSeparator(JSeparator.VERTICAL);
static JButton jbtTable01 = new JButton("Table 1");
static JButton jbtTable2 = new JButton("Table 2");
static JButton jbtTable3 = new JButton("Table 3");
static JButton jbtTable4 = new JButton("Table 4");
static JButton jbtTable5 = new JButton("Table 5");
static JButton jbtTable6 = new JButton("Table 6");
static JButton jbtTable7 = new JButton("Table 7");
static JButton jbtTable8 = new JButton("Table 8");
static JButton jbtTable9 = new JButton("Table 9");
static JButton jbtTable10 = new JButton("Table 10");
static JButton jbtTable11 = new JButton("Table 11");
static JButton jbtTable12 = new JButton("Table 12");
static JButton jbtTable13 = new JButton("Table 13");
static JButton jbtTable14 = new JButton("Table 14");
static JButton jbtTable15 = new JButton("Table 15");

static JComboBox jcbSeat = new JComboBox(seat);

JButton jbtBigTable = new JButton();
JButton jbtMedTable = new JButton();
JButton jbtSmallTable = new JButton();
JButton jbtNA = new JButton();
JButton jbtClose = new JButton("Close Window");

public RestaurantPlan(){
setLayout(null);

//Some Other Code...i guess is not related.

add(jbtTable9);add(jbtTable8);add(jbtTable7);
add(jbtTable6);add(jbtTable5);add(jbtTable4);
add(jbtTable3);add(jbtTable2);add(jbtTable01);

add(jlbCashier);
add(jlbRestroom);
add(jlbRestroom2);
add(jbtClose);

jbtTable01.addActionListener(this);
jbtClose.addActionListener( this);

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jbtTable01){
System.out.println("AAAAAAAAAAAAA");
}

if(e.getSource()==jbtClose){
System.out.println("ABC");
}
}
}


When i try open this frame for second time and click on jbtTable01, it will show the message twice, while on jbtClose, it will only show once...

what should be the problem? anyone could help me?


vince vinci

Posts: 2
Nickname: opera33
Registered: Mar, 2009

Re: JButton Problem Posted: Mar 27, 2009 11:51 AM
Reply to this message Reply
Problem solved.

this is caused by the "static" modifier.

Futher explaination can be found here

http://forums.sun.com/thread.jspa?messageID=10659078

Flat View: This topic has 1 reply on 1 page
Topic: [ANN] nWire 1.0 Released: Innovative Plugin For Java Code Exploration Previous Topic   Next Topic Topic: I need help!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use