Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-23-2007, 06:05 PM
Member
 
Join Date: Jul 2007
Posts: 2
bluebirdjc is on a distinguished road
gui problems
hello all i have a problem with a gui program i have created.

Code:
import java.io.*; // for file writing part of assignment import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.BorderLayout; import java.util.*; public class Marina implements ActionListener { JButton exit = new JButton("exit"); String timearrive, timeleave; JButton enter = new JButton("submit button"); String[] priceStrings = { "Hour", "Daily", "Weekly", "Monthly", "Annual" }; JTextField cname = new JTextField(10); JTextField clength = new JTextField(10); private JComboBox pricerate; //This is a Graphical User Interface built in a Java application for the //java revisited courrsework public Marina(){ JFrame Marina = new JFrame(); //I am now using panels display labels, Buttons etc which will be used to create the gui inerface JLabel welcomelabel = new JLabel("please enter your details below"); welcomelabel.setPreferredSize(new Dimension(175,100)); welcomelabel.setForeground(Color.red); JPanel FirstPanel = new JPanel(); FirstPanel.add(welcomelabel); JLabel label1 = new JLabel("Full Name"); label1.setPreferredSize(new Dimension(175,100)); label1.setForeground(Color.red); JLabel label2 = new JLabel("Length of yatch"); label2.setPreferredSize(new Dimension(175,100)); label2.setForeground(Color.red); JLabel label3 = new JLabel("Rate you would like"); label3.setPreferredSize(new Dimension(175,100)); label3.setForeground(Color.red); JLabel label4 = new JLabel("Price Rates available"); label4.setPreferredSize(new Dimension(175,100)); label4.setForeground(Color.red); JLabel label5 = new JLabel("Hourly Rate £0.50"); label5.setPreferredSize(new Dimension(175,100)); label5.setForeground(Color.red); JLabel label6 = new JLabel("Daily Rate £1.00"); label6.setPreferredSize(new Dimension(175,100)); label6.setForeground(Color.red); JLabel label7 = new JLabel("Weekly Rate £6.30"); label7.setPreferredSize(new Dimension(175,100)); label7.setForeground(Color.red); JLabel label8 = new JLabel("Monthly Rate £19.00"); label8.setPreferredSize(new Dimension(175,100)); label8.setForeground(Color.red); JLabel label9 = new JLabel("Annual Rate £132.00"); label9.setPreferredSize(new Dimension(175,100)); label9.setForeground(Color.red); enter.addActionListener(this); exit.addActionListener(this); cname.addActionListener(this); clength.addActionListener(this); pricerate = new JComboBox(priceStrings); pricerate.setSelectedIndex(1); pricerate.addActionListener(this); JPanel SecondPanel = new JPanel(); SecondPanel.add(label1); SecondPanel.add(cname); SecondPanel.add(label2); SecondPanel.add(clength); SecondPanel.add(label3); SecondPanel.add(pricerate); SecondPanel.add(exit); SecondPanel.add(enter); JPanel ThirdPanel = new JPanel(); ThirdPanel.add(label4); ThirdPanel.add(label5); ThirdPanel.add(label6); ThirdPanel.add(label7); ThirdPanel.add(label8); ThirdPanel.add(label9); JPanel FourthPanel = new JPanel(); // add boat image or something here if got time JPanel FifthPanel = new JPanel();; // add boat image or something here if got time //i am now going to add the panels to the frame so all the labels and //textfields etc are displayed Marina.getContentPane().add(FirstPanel, BorderLayout.NORTH); Marina.getContentPane().add(SecondPanel, BorderLayout.CENTER); Marina.getContentPane().add(ThirdPanel, BorderLayout.WEST); Marina.getContentPane().add(FourthPanel, BorderLayout.EAST); Marina.getContentPane().add(FifthPanel, BorderLayout.SOUTH); Marina.pack(); Marina.setVisible(true); } public void actionPerformed(ActionEvent e) { //if command for when the user wants an hourly rate if ( e.getSource() == exit ) { System.exit(0); //still not working find out why } //got to edit so if user presses button then something happens else if ( e.getSource() == enter ) { if (((String)pricerate.getSelectedItem()).equals("hour")) { timearrive = JOptionPane.showInputDialog("please enter time you wish to enter the marina"); timeleave = JOptionPane.showInputDialog(" please enter time you wish to leave the marina"); //gonna use the scanner now to put input into cdetails text file String name = cname.getText(); int length = Integer.parseInt(length.getText()); String price.getSelectedItem(length,getText()); //Strings to be edited so time customers arrives and leaves can be stored in file String arrival = String leave = JOptionPane.showMessageDialog(null,"Thank you for your custom and will contact you shortly to confirm your booking"); //import a scanner class here } } // a file writer to be inserted later to write customer details into the program //I have imported a sperate class into this class containing the code for the filewirting process //if user gives one of the other rates else { //import price class here JOptionPane.showMessageDialog(null, "Thank you for your custom we have stored your details and will contact you shortly to confirm your booking"); } // import a scanner class here //I have improted a sperate class into this class containing the code for the filewirting process } //the main method for my program public static void main(String[] args) throws IOException { //I have created the gui new Marina(); } }
at the moment a gui is displaying but changes have been made since then.

the main things i want to do are

my joption panes show up when i change options on my jcombobox but i want them to show up only when i press the submit button. the command i have wrote to try and do this is in my actionperformed method.

i have created strings called arrival and leave from which i wish to get the text entered into the input joption panes timearrive and timeleave but i am unsure of the command needed to be written to do this

also i have this other class ( i would use a scanner but have been told to use a filweriter and been given example code to help me create the class) which i want to write the strings etc into a document i have created called cdetails.txt but currently has problems. i plan to put this class into my program as shown as above later on when correct

Code:
import java.util.*; import java.io.*; public class WriteToFile2 { String name, price, arrival, leave; int length; public static void main(String args[]) { try { FileWriter fw = new FileWriter ("cdetails.txt"); BufferedWriter out = new BufferedWriter(fw); // need to get a enter command or something working here out.write(""); out.write(name + " " + length + " " + price + " " + arrival + " " + leave + " "); } catch (IOException e) {} } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-23-2007, 06:28 PM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
I like to know the following details to help you
1) What you try to achieve ?
2) Please give the latest code ?
3) actionperformed method is empty , where are string checking done ?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-23-2007, 06:38 PM
Member
 
Join Date: Jul 2007
Posts: 2
bluebirdjc is on a distinguished road
sorry problems in my alignment and this is the latest code

i am required to design and implement a java application to keep track of the time a yatch is moored at Cardiff Marina then calculate charges due when the owner wishes to sail. it should also ask for users information eg name etc.

Should create a gui to do this and if the user wants an hourly rate then the program should prompt them for the time they enter the marina and the time they leave using a joptionpane. then the data should be entered into a text file

Code:
import java.io.*; // for file writing part of assignment import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JPanel; import java.awt.BorderLayout; import java.util.*; public class Marina implements ActionListener { JButton exit = new JButton("exit"); String timearrive, timeleave; JButton enter = new JButton("submit button"); String[] priceStrings = { "Hour", "Daily", "Weekly", "Monthly", "Annual" }; JTextField cname = new JTextField(10); JTextField clength = new JTextField(10); private JComboBox pricerate; //This is a Graphical User Interface built in a Java application for the //java revisited courrsework public Marina(){ JFrame Marina = new JFrame(); //I am now using panels display labels, Buttons etc which will be used to create the gui inerface JLabel welcomelabel = new JLabel("please enter your details below"); welcomelabel.setPreferredSize(new Dimension(175,100)); welcomelabel.setForeground(Color.red); JPanel FirstPanel = new JPanel(); FirstPanel.add(welcomelabel); JLabel label1 = new JLabel("Full Name"); label1.setPreferredSize(new Dimension(175,100)); label1.setForeground(Color.red); JLabel label2 = new JLabel("Length of yatch"); label2.setPreferredSize(new Dimension(175,100)); label2.setForeground(Color.red); JLabel label3 = new JLabel("Rate you would like"); label3.setPreferredSize(new Dimension(175,100)); label3.setForeground(Color.red); JLabel label4 = new JLabel("Price Rates available"); label4.setPreferredSize(new Dimension(175,100)); label4.setForeground(Color.red); JLabel label5 = new JLabel("Hourly Rate £0.50"); label5.setPreferredSize(new Dimension(175,100)); label5.setForeground(Color.red); JLabel label6 = new JLabel("Daily Rate £1.00"); label6.setPreferredSize(new Dimension(175,100)); label6.setForeground(Color.red); JLabel label7 = new JLabel("Weekly Rate £6.30"); label7.setPreferredSize(new Dimension(175,100)); label7.setForeground(Color.red); JLabel label8 = new JLabel("Monthly Rate £19.00"); label8.setPreferredSize(new Dimension(175,100)); label8.setForeground(Color.red); JLabel label9 = new JLabel("Annual Rate £132.00"); label9.setPreferredSize(new Dimension(175,100)); label9.setForeground(Color.red); enter.addActionListener(this); exit.addActionListener(this); cname.addActionListener(this); clength.addActionListener(this); pricerate = new JComboBox(priceStrings); pricerate.setSelectedIndex(1); pricerate.addActionListener(this); JPanel SecondPanel = new JPanel(); SecondPanel.add(label1); SecondPanel.add(cname); SecondPanel.add(label2); SecondPanel.add(clength); SecondPanel.add(label3); SecondPanel.add(pricerate); SecondPanel.add(exit); SecondPanel.add(enter); JPanel ThirdPanel = new JPanel(); ThirdPanel.add(label4); ThirdPanel.add(label5); ThirdPanel.add(label6); ThirdPanel.add(label7); ThirdPanel.add(label8); ThirdPanel.add(label9); JPanel FourthPanel = new JPanel(); // add boat image or something here if got time JPanel FifthPanel = new JPanel();; // add boat image or something here if got time //i am now going to add the panels to the frame so all the labels and //textfields etc are displayed Marina.getContentPane().add(FirstPanel, BorderLayout.NORTH); Marina.getContentPane().add(SecondPanel, BorderLayout.CENTER); Marina.getContentPane().add(ThirdPanel, BorderLayout.WEST); Marina.getContentPane().add(FourthPanel, BorderLayout.EAST); Marina.getContentPane().add(FifthPanel, BorderLayout.SOUTH); Marina.pack(); Marina.setVisible(true); } public void actionPerformed(ActionEvent e) { //if command for when the user wants an hourly rate if ( e.getSource() == exit ) { System.exit(0); //still not working find out why } //got to edit so if user presses button then something happens else if ( e.getSource() == enter ) { if (((String)pricerate.getSelectedItem()).equals("hour")) { timearrive = JOptionPane.showInputDialog("please enter time you wish to enter the marina"); timeleave = JOptionPane.showInputDialog(" please enter time you wish to leave the marina"); //gonna use the scanner now to put input into cdetails text file String name = cname.getText(); int length = Integer.parseInt(length.getText()); String price.getSelectedItem(length,getText()); //Strings to be edited so time customers arrives and leaves can be stored in file String arrival = String leave = JOptionPane.showMessageDialog(null,"Thank you for your custom and will contact you shortly to confirm your booking"); //import a scanner class here } } // a file writer to be inserted later to write customer details into the program //I have imported a sperate class into this class containing the code for the filewirting process //if user gives one of the other rates else { //import price class here JOptionPane.showMessageDialog(null, "Thank you for your custom we have stored your details and will contact you shortly to confirm your booking"); } // import a scanner class here //I have improted a sperate class into this class containing the code for the filewirting process } //the main method for my program public static void main(String[] args) { //I have created the gui new Marina(); } }
at the moment a gui is displaying but changes have been made since then.

the main things i want to do are

my joption panes show up when i change options on my jcombobox but i want them to show up only when i press the submit button. the command i have wrote to try and do this is in my actionperformed method.

i have created strings called arrival and leave from which i wish to get the text entered into the input joption panes timearrive and timeleave but i am unsure of the command needed to be written to do this

also i have this other class ( i would use a scanner but have been told to use a filweriter and been given example code to help me create the class) which i want to write the strings etc into a document i have created called cdetails.txt but currently has problems. i plan to put this class into my program as shown as above later on when correct

Code:
import java.util.*; import java.io.*; public class WriteToFile2 { String name, price, arrival, leave; int length; public static void main(String args[]) { try { FileWriter fw = new FileWriter ("cdetails.txt"); BufferedWriter out = new BufferedWriter(fw); // need to get a enter command or something working here out.write(""); out.write(name + " " + length + " " + price + " " + arrival + " " + leave + " "); } catch (IOException e) {} } }

Last edited by bluebirdjc : 07-23-2007 at 06:43 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in JSP : Need help raj4u JavaServer Pages (JSP) and JSTL 1 02-07-2008 11:06 AM
GUI problems. saytri New To Java 1 12-16-2007 11:27 PM
a few problems gary AWT / Swing 0 07-11-2007 05:57 PM
problems with JPA Ed New To Java 2 07-04-2007 06:34 AM
Problems with the jar Freddie NetBeans 2 05-29-2007 04:50 PM


All times are GMT +3. The time now is 07:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org