Results 1 to 5 of 5
- 01-20-2011, 02:08 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
How to read data from .txt and update the status of button
Can anyone help me with this coding ?
I got no clue on how to implement the function ~
It's a booking system, when someone click the "Seat 1" or so on. The "Seat 1" should be changed to "BOOKED" but when the constructor run for the second time , the "BOOKED" disappear and reset back to "Seat 1".
Can anyone help me to solve this ?
Thanks in advance.import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FirstClassSeating extends JFrame{
private static final long serialVersionUID = 1L;
JButton fcButton[] = new JButton[20];
JButton returnButton = new JButton("RETURN");
JLabel titleLabel = new JLabel("First Class Seating");
JLabel aisleLabel = new JLabel("Aisle");
JPanel buttonPanelL = new JPanel();
JPanel buttonPanelR = new JPanel();
JPanel returnPanel = new JPanel();
JPanel titlePanel = new JPanel();
JPanel aislePanel = new JPanel();
public String str;
public int number;
public FirstClassSeating(){
setLayout(new BorderLayout());
setPreferredSize(new Dimension(450,450));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setTitle("First Class Seating");
//aisle
aisleLabel.setBorder(new javax.swing.border.EmptyBorder(new Insets(0, 0, 0, 0)));
aislePanel.add(aisleLabel);
getContentPane().add(aislePanel,BorderLayout.CENTE R);
//title
titlePanel.setBorder(new javax.swing.border.EtchedBorder());
titleLabel.setBorder(new javax.swing.border.EmptyBorder(new Insets(1, 1, 1, 1)));
titlePanel.add(titleLabel);
getContentPane().add(titlePanel,BorderLayout.NORTH );
//button panel
returnPanel.setLayout(new GridLayout(1,1,4,4));
returnPanel.setBorder(new javax.swing.border.EtchedBorder());
buttonPanelL.setLayout(new GridLayout(5,2,4,4));
buttonPanelL.setBorder(new javax.swing.border.EtchedBorder());
buttonPanelR.setLayout(new GridLayout(5,2,4,4));
buttonPanelR.setBorder(new javax.swing.border.EtchedBorder());
returnPanel.add(returnButton);
//buttons
for(int i=0; i<10; i++){
fcButton[i] = new JButton();
if(fcButton[i].getText() != "Booked"){
fcButton[i].setText("Seat"+(i+1));
buttonPanelL.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
else{
fcButton[i].setText("Booked");
buttonPanelL.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
}
for(int i=10; i<20; i++){
fcButton[i] = new JButton();
if(fcButton[i].getText() != "Booked"){
fcButton[i].setText("Seat"+(i+1));
buttonPanelR.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
else{
fcButton[i].setText("Booked");
buttonPanelL.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
}
getContentPane().add(buttonPanelL,BorderLayout.WES T);
getContentPane().add(buttonPanelR,BorderLayout.EAS T);
getContentPane().add(returnPanel,BorderLayout.SOUT H);
returnButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
returnButtonActionPerformed(e);
}
}
);
}
public void ButtonActionPerformed(ActionEvent e){
for(int i=0; i<20; i++){
if(e.getSource() == fcButton[i]){
str = fcButton[i].getText();
JOptionPane.showMessageDialog(null,"This is: "+str);
}
}
}
@SuppressWarnings("deprecation")
public void returnButtonActionPerformed(ActionEvent e){
this.hide();
ChooseClass cc = new ChooseClass();
cc.showAndDisplayGUI();
}
public void showAndDisplayGUI(){
FirstClassSeating fcs = new FirstClassSeating();
fcs.pack();
fcs.setVisible(true);
}
public static void main(String a[]){
FirstClassSeating fcs = new FirstClassSeating();
fcs.pack();
fcs.setVisible(true);
}
}Last edited by jian0203; 01-20-2011 at 02:26 PM.
-
Rather than download a whole program, please create a small compilable program that demonstrates your problem (an SSCCE), and then post the code in the forum with code tags. We're all volunteers and appreciate it when posters put in effort to simplify their problem and make it easier for us to solve. Luck.
- 01-20-2011, 04:43 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Also please use proper indentation. I suspect the forum blatted your code before you stuck the tags in.
I do question this though:
Java Code:public void showAndDisplayGUI() { FirstClassSeating fcs = new FirstClassSeating(); fcs.pack(); fcs.setVisible(true); }
-
- 01-20-2011, 04:52 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Need to Save a data to file from JPanel and read the data back to Jpanel
By yashrajsen in forum AWT / SwingReplies: 1Last Post: 11-09-2010, 09:28 AM -
Update JTable data
By DC200 in forum AWT / SwingReplies: 8Last Post: 03-30-2010, 10:10 PM -
Read file from directory, update contents of the each file
By svpriyan in forum New To JavaReplies: 2Last Post: 05-11-2009, 10:07 AM -
How to update data for a JPA many-to-many relationship?
By abhijit.sarkar in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 11-04-2008, 08:48 AM -
[SOLVED] Update jTable with new data (especially Date value Format)
By gustio in forum New To JavaReplies: 2Last Post: 08-12-2008, 12:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks