Wrox Programmer Forums
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2007, 06:46 AM
Registered User
 
Join Date: Mar 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Save button

i have to create a save button with java code and i have no idea how to do it. i have created a button
can someone help please
the code is shown below

// Demonstrating the JLabel class.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class pottery extends JFrame {
   private JLabel label1,label2,label3,label4,label5,label6,label7,l abel8,label9,label10,label11,label12,label13,label 14,label15,label16,label17,label18,label19,label20 ,label21,label22;
   private JButton button1;
   private ButtonGroup gbutton;
   private JTextField text,text1,text2,text3,text4,text5;
   private JComboBox Combo1,Combo2,Combo3,Combo4,Combo5,Combo6,Combo7,C ombo8,Combo9,Combo10,Combo11;

String[] combo = {"1", "2", "3", "4", "5", "6"};
String[] combo1 = {"Shropshire", "Cornwall", "SW France", "East Anglia"};
String[] combo2 = {"9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00"};
String[] combo3 = {"Smoking", "Non-Smoking"};
String[] combo4 = {"Adult", "Child", "Disabled"};
String[] combo5 = {"Economy", "First Class"};
String[] combo6 = {"Beginner", "Intermediate", "Advanced"};
String[] combo7 = {"Mr", "Mrs", "Miss"};
String[] combo8 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
String[] combo9 = {"January", "Februrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};


 public pottery()
   {
      super( "Airline Booking Form" );

      Container c = getContentPane();
      c.setLayout( new FlowLayout(FlowLayout.CENTER, 30,30));
      // JLabel constructor with a string argument
      label1 = new JLabel( "Airline Booking Form" );
      label1.setToolTipText( "Airline Booking Form" );
      c.add( label1 );


//LABEL

      label2 = new JLabel( "Customer Information" );
      c.add( label2 );

      label3 = new JLabel( "Title" );
      c.add( label3 );

//COMBOBOX

      Combo8 = new JComboBox(combo7);
      Combo8.setToolTipText("This is a Combo Box");
      c.add(Combo8);

      label4 = new JLabel( "First Name" );
      c.add( label4 );

//TEXTBOX

      text = new JTextField (10);
      c.add(text);

      label5 = new JLabel( "Surname" );
      c.add( label5 );

      text1 = new JTextField (10);
      c.add(text1);

      label6 = new JLabel( "Address 1" );
      c.add( label6 );

      text2= new JTextField (10);
      c.add(text2);

      label7= new JLabel( "Address 2" );
      c.add( label7 );

      text3 = new JTextField (10);
      c.add(text3);

      label8 = new JLabel( "City" );
      c.add( label8 );

      text4 = new JTextField (10);
      c.add(text4);

      label9 = new JLabel( "Postcode" );
      c.add( label9 );

      text5 = new JTextField (8);
      c.add(text5);

      label10 = new JLabel( "Ticket Information" );
      c.add( label10 );

      label11 = new JLabel( "Departure Date" );
      c.add( label11 );

      label12 = new JLabel( "Day" );
      c.add( label12 );

      Combo9 = new JComboBox(combo8);
      Combo9.setToolTipText("This is a Combo Box");
      c.add(Combo9);

      label13 = new JLabel( "Month" );
      c.add( label13 );

      Combo10 = new JComboBox(combo9);
      Combo10.setToolTipText("This is a Combo Box");
      c.add(Combo10);

      label14 = new JLabel( "Return Date" );
      c.add( label14 );

      label15 = new JLabel( "Day" );
      c.add( label15 );

      Combo9 = new JComboBox(combo8);
      Combo9.setToolTipText("This is a Combo Box");
      c.add(Combo9);

      label13 = new JLabel( "Month" );
      c.add( label13 );

      Combo10 = new JComboBox(combo9);
      Combo10.setToolTipText("This is a Combo Box");
      c.add(Combo10);

      label18 = new JLabel( "Number of Tickets" );
      c.add( label18 );

      Combo1 = new JComboBox(combo);
      Combo1.setToolTipText("This is a Combo Box");
      c.add(Combo1);

      label19 = new JLabel( "Destination" );
      c.add( label19 );

      Combo2 = new JComboBox(combo1);
      Combo2.setToolTipText("This is a Combo Box");
      c.add(Combo2);

      label20 = new JLabel( "Passenger Type" );
      c.add( label20 );

      Combo5 = new JComboBox(combo4);
      Combo5.setToolTipText("This is a Combo Box");
      c.add(Combo5);

      label21 = new JLabel( "Ticket Type" );
      c.add( label21 );

      Combo6 = new JComboBox(combo5);
      Combo6.setToolTipText("This is a Combo Box");
      c.add(Combo6);

      label17 = new JLabel( "Seat Preference" );
      c.add( label17 );

      Combo4 = new JComboBox(combo3);
      Combo4.setToolTipText("This is a Combo Box");
      c.add(Combo4);

      label22 = new JLabel( "Pottery Package Type" );
      c.add( label22 );

      Combo7 = new JComboBox(combo6);
      Combo7.setToolTipText("This is a Combo Box");
      c.add(Combo7);

//BUTTON

      button1 = new JButton("Save");
      c.add(button1);



      setSize( 500, 600 );
      setVisible(true);


   }

   public static void main( String args[] )
   {
      pottery app = new pottery();

      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }
}
 
Old April 16th, 2007, 11:44 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
You've not explained your problem clearly, what i understand is you want to save the data given in the fields when user click on the Save button you've created.

For that you need to user event listeners [to recieve the click events on the button] in perticular ActionListener interface it has one method actionPerformed(ActionEvent e){} which you need to override and write the code which you want to use for saving the data.
And dont forget to add the actionlister to the button using addActionListener() method of the JButton

i.e button1.addActionListener(actionlisternobject);

Regards,
Rakesh
:)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Overflow Problem in ToolStrip Save button zaki79 VB Databases Basics 2 June 5th, 2008 01:38 PM
avoid getting save confirmation on button click sansircar .NET Framework 1.x 1 February 1st, 2006 12:52 AM
how to show a button when save is done noor ASP.NET 1.0 and 1.1 Basics 4 May 9th, 2005 12:49 AM
When I hit save button the selected employee clear shoakat Classic ASP Databases 6 September 16th, 2004 01:41 AM
onclick button, we want to save our company profil pawan Javascript 3 September 26th, 2003 07:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.