473,473 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

weird java question

53 New Member
im pretty new to java. this might sound like a weird question but! how do i add this code
Expand|Select|Wrap|Line Numbers
  1. class FileWrite
  2. {
  3.    public static void main(String args[])
  4.   {
  5.       try{
  6.     // Create file 
  7.     FileWriter fstream = new FileWriter("out.txt");
  8.         BufferedWriter out = new BufferedWriter(fstream);
  9.     out.write("Hello Java");
  10.     //Close the output stream
  11.     out.close();
  12.     }catch (Exception e){//Catch exception if any
  13.       System.err.println("Error: " + e.getMessage());
  14.     }
  15.   }
  16. }
  17.  
  18.  
  19.  
  20.  
  21. too...........
  22.  
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import javax.swing.*;
  27.  
  28. public class Main
  29. {
  30.         JFrame f1;
  31.         JPanel p1,p2;
  32.        boolean clearall = false;
  33.         GP g1;
  34.         JButton Bok,Bcc,clear,submit;
  35.         JTextField first,last,age,street,city,gender;
  36.         JLabel firstl,lastl,agel,streetl,cityl,genderl,monthl,statel,yearl;
  37.     public Main()
  38.     {  
  39.  
  40.  
  41.         String[] year = { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008" , "2009", "2010"};
  42.  
  43.         firstl = new JLabel("First Name");
  44.         lastl = new JLabel("Last Name");
  45.         agel = new JLabel("Age");
  46.         streetl = new JLabel("Street");
  47.         cityl = new JLabel("City");
  48.         genderl = new JLabel("Gender");
  49.         monthl = new JLabel("Month");
  50.         statel = new JLabel("State");
  51.         yearl = new JLabel("Year");
  52.         JComboBox yearcombo = new JComboBox(year);
  53.         yearcombo.setSelectedIndex(29);
  54.  
  55.          yearcombo.setEditable(false);
  56.         String[] month = { "January", "Febuary", "March", "April", "May", "June", "July", "October", "November", "December"};
  57.         JComboBox monthcombo = new JComboBox(month);
  58.         monthcombo.setEditable(false);
  59.         monthcombo.setSelectedIndex(9);
  60.  
  61.         String[] state = { "Alabama AL", "Alaska AK" ,"Arizona AZ", "Arkansas AR", "California CA" ,"Colorado CO", "Connecticut CT" ,"Delaware DE", "Florida FL","Georgia GA", "Hawaii HI"," Idaho ID","Illinois IL" ,"Indiana IN", "Iowa IA", "Kansas KS" ,"Kentucky KY" ,"Louisiana LA", "Maine ME", "Maryland MD" ,"Massachusetts MA", "Michigan MI" ,"Minnesota MN" ,"Mississippi MS" ,"Missouri MO", "Montana MT" ,"Nebraska NE", "Nevada NV" ,"New Hampshire NH" ,"New Jersey NJ", "New Mexico NM", "New York NY", "North Carolina NC", "North Dakota ND" ,"Ohio OH" ,"Oklahoma OK", "Oregon OR" ,"Pennsylvania PA" ,"Rhode Island RI", "South Carolina SC", "South Dakota SD" ,"Tennessee TN", "Texas TX" ,"Utah UT", "Vermont VT" ,"Virginia VA" ,"Washington WA", "West Virginia WV", "Wisconsin WI" ,"Wyoming WY"};
  62.         JComboBox statecombo = new JComboBox(state);
  63.         statecombo.setSelectedIndex(49);
  64.  
  65.         String[] gender = {"M","F"};
  66.         JComboBox gendercombo = new JComboBox(gender);
  67.         gendercombo.setSelectedIndex(1);
  68.  
  69.         gendercombo.setEditable(false);
  70.  
  71.         MyActionListener actionListener = new MyActionListener();
  72.     yearcombo.addActionListener(actionListener);
  73.  
  74.     gendercombo.addActionListener(actionListener);
  75.  
  76.     statecombo.addActionListener(actionListener);
  77.         f1 = new JFrame("fafafffdas");
  78.           f1.setSize(832,200);        
  79.         Container c1 = f1.getContentPane();
  80.  
  81.  
  82.         p1 = new JPanel();
  83.         p1.setSize(1000,200);
  84.         p1.setLayout(new BorderLayout());
  85.  
  86.         first = new JTextField("");
  87.         last = new JTextField("");
  88.         age = new JTextField("");
  89.         street = new JTextField("");
  90.         city = new JTextField("");
  91.         clear = new JButton("Clear");
  92.         clear.addActionListener(new ButtonListener());
  93.         submit = new JButton("Submit");
  94.         submit.addActionListener(new ButtonListener());
  95.         Bok = new JButton("Save");
  96.          Bok.addActionListener(new ButtonListener());
  97.         Bcc = new JButton("Quit");
  98.          Bcc.addActionListener(new ButtonListener());
  99.  
  100.  
  101.  
  102.           // Get number of items
  103.        //  int numyear = yearcombo.getItemCount();
  104.       // int numgender = statecombo.getItemCount();
  105.       // int numstate = gendercombo.getItemCount();
  106.  
  107.  
  108.  
  109.         p2 = new JPanel();  //panel to add JLabel and TextField
  110.  
  111.         g1 = new GP();    
  112.          p1.add(g1,BorderLayout.CENTER);
  113.  
  114.         g1.add(firstl);  
  115.         g1.add(first);
  116.         g1.add(lastl);
  117.         g1.add(last);
  118.         g1.add(agel);
  119.         g1.add(age);
  120.         g1.add(yearl);
  121.         g1.add(yearcombo);
  122.         g1.add(genderl);
  123.         g1.add(gendercombo);
  124.         g1.add(streetl);
  125.         g1.add(street);
  126.         g1.add(cityl);
  127.         g1.add(city);
  128.         g1.add(statel);
  129.         g1.add(statecombo);
  130.         p2.add(submit);
  131.         p2.add(Bok);
  132.         p2.add(clear);
  133.         p2.add(Bcc);
  134.  
  135.         p1.add(p2,BorderLayout.SOUTH);      //adds p2 to south (Bottom) Graphics Panel will be added to Center    
  136.         c1.add(p1);
  137.  
  138.         f1.show();
  139.  
  140.     }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.      public class MyActionListener implements ActionListener
  151.      {
  152.         public void actionPerformed(ActionEvent evt)
  153.         {
  154.             JComboBox yearcombo = (JComboBox)event.getSource();
  155.  
  156.             // Get the new item
  157.             Object stateselect = yearcombo.getSelectedItem();
  158.  
  159.         }
  160.         {
  161.             JComboBox gendercombo = (JComboBox)evt.getSource();
  162.  
  163.             // Get the new item
  164.             Object genderselect = gendercombo.getSelectedItem();
  165.  
  166.         }
  167.         {
  168.            JComboBox statecombo = (JComboBox)evt.getSource();
  169.  
  170.             // Get the new item
  171.             Object stateselect = statecombo.getSelectedItem();
  172.  
  173.         }
  174.     }
  175.  
  176.     private class ButtonListener implements ActionListener
  177.     {
  178.       public void actionPerformed (ActionEvent event)
  179.       {
  180.  
  181.  
  182.         if (event.getSource() == clear)
  183.         {
  184.             clearall = true;
  185.  
  186.         }    
  187.  
  188.         if (event.getSource() == Bok)
  189.            {
  190.                g1.requestFocus();
  191.  
  192.            }
  193.  
  194.         if (event.getSource() == Bcc)
  195.            {
  196.  
  197.                f1.dispose();
  198.            }
  199.         if (event.getSource() == submit)
  200.         {
  201.  
  202.  
  203.         }
  204.  
  205.           g1.repaint();  
  206.         }
  207.     }
  208.  
  209.  
  210. }
Sep 25 '07 #1
2 1711
r035198x
13,262 MVP
im pretty new to java. this might sound like a weird question but! how do i add this code
What do you mean by "add this code"?
Sep 25 '07 #2
Nepomuk
3,112 Recognized Expert Specialist
im pretty new to java. this might sound like a weird question but! how do i add this code...
Just put it underneath the other part:
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Main
  6. {
  7.         JFrame f1;
  8.         JPanel p1,p2;
  9.        boolean clearall = false;
  10.         GP g1;
  11.         JButton Bok,Bcc,clear,submit;
  12.         JTextField first,last,age,street,city,gender;
  13.         JLabel firstl,lastl,agel,streetl,cityl,genderl,monthl,statel,yearl;
  14.     public Main()
  15.     {  
  16.  
  17.  
  18.         String[] year = { "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008" , "2009", "2010"};
  19.  
  20.         firstl = new JLabel("First Name");
  21.         lastl = new JLabel("Last Name");
  22.         agel = new JLabel("Age");
  23.         streetl = new JLabel("Street");
  24.         cityl = new JLabel("City");
  25.         genderl = new JLabel("Gender");
  26.         monthl = new JLabel("Month");
  27.         statel = new JLabel("State");
  28.         yearl = new JLabel("Year");
  29.         JComboBox yearcombo = new JComboBox(year);
  30.         yearcombo.setSelectedIndex(29);
  31.  
  32.          yearcombo.setEditable(false);
  33.         String[] month = { "January", "Febuary", "March", "April", "May", "June", "July", "October", "November", "December"};
  34.         JComboBox monthcombo = new JComboBox(month);
  35.         monthcombo.setEditable(false);
  36.         monthcombo.setSelectedIndex(9);
  37.  
  38.         String[] state = { "Alabama AL", "Alaska AK" ,"Arizona AZ", "Arkansas AR", "California CA" ,"Colorado CO", "Connecticut CT" ,"Delaware DE", "Florida FL","Georgia GA", "Hawaii HI"," Idaho ID","Illinois IL" ,"Indiana IN", "Iowa IA", "Kansas KS" ,"Kentucky KY" ,"Louisiana LA", "Maine ME", "Maryland MD" ,"Massachusetts MA", "Michigan MI" ,"Minnesota MN" ,"Mississippi MS" ,"Missouri MO", "Montana MT" ,"Nebraska NE", "Nevada NV" ,"New Hampshire NH" ,"New Jersey NJ", "New Mexico NM", "New York NY", "North Carolina NC", "North Dakota ND" ,"Ohio OH" ,"Oklahoma OK", "Oregon OR" ,"Pennsylvania PA" ,"Rhode Island RI", "South Carolina SC", "South Dakota SD" ,"Tennessee TN", "Texas TX" ,"Utah UT", "Vermont VT" ,"Virginia VA" ,"Washington WA", "West Virginia WV", "Wisconsin WI" ,"Wyoming WY"};
  39.         JComboBox statecombo = new JComboBox(state);
  40.         statecombo.setSelectedIndex(49);
  41.  
  42.         String[] gender = {"M","F"};
  43.         JComboBox gendercombo = new JComboBox(gender);
  44.         gendercombo.setSelectedIndex(1);
  45.  
  46.         gendercombo.setEditable(false);
  47.  
  48.         MyActionListener actionListener = new MyActionListener();
  49.     yearcombo.addActionListener(actionListener);
  50.  
  51.     gendercombo.addActionListener(actionListener);
  52.  
  53.     statecombo.addActionListener(actionListener);
  54.         f1 = new JFrame("fafafffdas");
  55.           f1.setSize(832,200);        
  56.         Container c1 = f1.getContentPane();
  57.  
  58.  
  59.         p1 = new JPanel();
  60.         p1.setSize(1000,200);
  61.         p1.setLayout(new BorderLayout());
  62.  
  63.         first = new JTextField("");
  64.         last = new JTextField("");
  65.         age = new JTextField("");
  66.         street = new JTextField("");
  67.         city = new JTextField("");
  68.         clear = new JButton("Clear");
  69.         clear.addActionListener(new ButtonListener());
  70.         submit = new JButton("Submit");
  71.         submit.addActionListener(new ButtonListener());
  72.         Bok = new JButton("Save");
  73.          Bok.addActionListener(new ButtonListener());
  74.         Bcc = new JButton("Quit");
  75.          Bcc.addActionListener(new ButtonListener());
  76.  
  77.  
  78.  
  79.           // Get number of items
  80.        //  int numyear = yearcombo.getItemCount();
  81.       // int numgender = statecombo.getItemCount();
  82.       // int numstate = gendercombo.getItemCount();
  83.  
  84.  
  85.  
  86.         p2 = new JPanel();  //panel to add JLabel and TextField
  87.  
  88.         g1 = new GP();    
  89.          p1.add(g1,BorderLayout.CENTER);
  90.  
  91.         g1.add(firstl);  
  92.         g1.add(first);
  93.         g1.add(lastl);
  94.         g1.add(last);
  95.         g1.add(agel);
  96.         g1.add(age);
  97.         g1.add(yearl);
  98.         g1.add(yearcombo);
  99.         g1.add(genderl);
  100.         g1.add(gendercombo);
  101.         g1.add(streetl);
  102.         g1.add(street);
  103.         g1.add(cityl);
  104.         g1.add(city);
  105.         g1.add(statel);
  106.         g1.add(statecombo);
  107.         p2.add(submit);
  108.         p2.add(Bok);
  109.         p2.add(clear);
  110.         p2.add(Bcc);
  111.  
  112.         p1.add(p2,BorderLayout.SOUTH);      //adds p2 to south (Bottom) Graphics Panel will be added to Center    
  113.         c1.add(p1);
  114.  
  115.         f1.show();
  116.  
  117.     }
  118.  
  119.      public class MyActionListener implements ActionListener
  120.      {
  121.         public void actionPerformed(ActionEvent evt)
  122.         {
  123.             JComboBox yearcombo = (JComboBox)event.getSource();
  124.  
  125.             // Get the new item
  126.             Object stateselect = yearcombo.getSelectedItem();
  127.  
  128.         }
  129.         {
  130.             JComboBox gendercombo = (JComboBox)evt.getSource();
  131.  
  132.             // Get the new item
  133.             Object genderselect = gendercombo.getSelectedItem();
  134.  
  135.         }
  136.         {
  137.            JComboBox statecombo = (JComboBox)evt.getSource();
  138.  
  139.             // Get the new item
  140.             Object stateselect = statecombo.getSelectedItem();
  141.  
  142.         }
  143.     }
  144.  
  145.     private class ButtonListener implements ActionListener
  146.     {
  147.       public void actionPerformed (ActionEvent event)
  148.       {
  149.  
  150.  
  151.         if (event.getSource() == clear)
  152.         {
  153.             clearall = true;
  154.  
  155.         }    
  156.  
  157.         if (event.getSource() == Bok)
  158.            {
  159.                g1.requestFocus();
  160.  
  161.            }
  162.  
  163.         if (event.getSource() == Bcc)
  164.            {
  165.  
  166.                f1.dispose();
  167.            }
  168.         if (event.getSource() == submit)
  169.         {
  170.  
  171.  
  172.         }
  173.  
  174.           g1.repaint();  
  175.         }
  176.     }
  177. }
  178.  
  179.  
  180. class FileWrite
  181. {
  182.    public static void main(String args[])
  183.   {
  184.       try{
  185.     // Create file 
  186.     FileWriter fstream = new FileWriter("out.txt");
  187.         BufferedWriter out = new BufferedWriter(fstream);
  188.     out.write("Hello Java");
  189.     //Close the output stream
  190.     out.close();
  191.     }catch (Exception e){//Catch exception if any
  192.       System.err.println("Error: " + e.getMessage());
  193.     }
  194.   }
  195. }
Sep 25 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Stephan & Saori | last post by:
I found a "weird" problem running windows 2003 Server. Maybe it's a know problem but I just wanted to make sure everyone knows. When running explorer to find the directories on my hard disk. It's...
1
by: Minti | last post by:
Hi there all, I am having a weird problem in the following Applet code, <begin code> public class MouseInputTester extends java.applet.Applet { private String msg = ""; private int mouseX ;...
0
by: Naren | last post by:
I have an XML like the one below. I am using SAX parsing and I need to get the information between the tags of the Email element. First i try to access the content and print it out and it gives...
82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
5
by: Frances Del Rio | last post by:
I'm connected to internet via Comcast cable modem, very fast connection, usu. have no problems, but all of a sudden there are a number of sites I can't get to (while others no problem.. very...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
10
by: David Thole | last post by:
Hey all, I'm still very new at all this, but am going through the ASP.net 2.0 unleashed book, first chapter and trying to program my own little form emailer for fun. I tried following the code...
5
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
3
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.