JAVA URGENT HELP

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

Urgent help needed.....My program is not running.......some simple mistakes are killing me. Anybody help me...... import javax.swing.*; import java.awt.*; import java.awt.event.*; class hello extends JFrame{   private JButton buttonPrev=new JButton("Prev");   private JButton buttonReset=new JButton("Reset");   private JButton buttonNext=new JButton("Next");   private JLabel labelHeader=new JLabel("Database Browser",JLabel.CENTER);   private JLabel labelName=new JLabel("Name");   private JLabel labelAddress=new JLabel("Address");   private JLabel labelCity=new JLabel("City");   private JLabel labelState=new JLabel("State");   private JLabel labelZip=new JLabel("Zip");   private JTextField textFieldName=new JTextField();   private JTextField textFieldAddress=new JTextField();   private JTextField textFieldCity=new JTextField();   private JTextField textFieldState=new JTextField();   private JTextField textFieldZip=new JTextField();      DataClass [] DataClassArray = { new DataClass("Fred", "Wayne", "101 Here", "NE", "55551"),                             new DataClass("Goerge", "Thomas", "102 There", "ME", "55552"),                             new DataClass("Mike", "Johnson", "103 No Where", "OK", "55553") };   int arrayPointer=0;      public Assignment_2_2(String title){     super(title);          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);     JPanel cp=(JPanel)getContentPane();     labelHeader.setFont(new Font("Verdana",Font.BOLD,24));     labelHeader.setBounds(40,10,300,50);     buttonPrev.setBounds(30,250,80,25);     buttonReset.setBounds(150,250,80,25);     buttonNext.setBounds(270,250,80,25);     labelName.setBounds(10,80,80,25);     labelAddress.setBounds(10,110,80,25);     labelCity.setBounds(10,140,80,25);     labelState.setBounds(10,170,80,25);     labelZip.setBounds(10,200,80,25);     textFieldName.setBounds(120,80,250,25);     textFieldAddress.setBounds(120,110,250,25);     textFieldCity.setBounds(120,140,250,25);     textFieldState.setBounds(120,170,250,25);     textFieldZip.setBounds(120,200,250,25);     cp.setLayout(null);     cp.add(labelHeader);     cp.add(buttonPrev);     cp.add(buttonReset);     cp.add(buttonNext);     cp.add(labelName);     cp.add(textFieldName);     cp.add(labelAddress);     cp.add(textFieldAddress);     cp.add(labelCity);     cp.add(textFieldCity);     cp.add(labelState);     cp.add(textFieldState);     cp.add(labelZip);     cp.add(textFieldZip);     addWindowListener(new java.awt.event.WindowAdapter() {       public void windowClosing(java.awt.event.WindowEvent evt) {         shutDown();       }     });    buttonPrevious.addActionListener(new java.awt.event.ActionListener()  {   //if the Previous button is pressed, show the Previous value in the DataClassArray.       public void actionPerformed(java.awt.event.ActionEvent evt)    {         if(arrayPointer > 0)   {           --arrayPointer;     setFields(arrayPointer);         }       }     });//End of the buttonPrevious Acction  //Event for the Next Button.  buttonNext.addActionListener(new java.awt.event.ActionListener()  {  DataClassArray.   //if the Next button is pressed, show the Next value in the DataClassArray       public void actionPerformed(java.awt.event.ActionEvent evt)    {         if (arrayPointer >= 0 && arrayPointer < 2)   {    ++arrayPointer;    setFields(arrayPointer);   }       }     });//End of the buttonNext Action.  //Event for the Reset Button.  buttonReset.addActionListener(new java.awt.event.ActionListener()  {       //if the reset button is pressed, show the first value in the DataClassArray.    public void actionPerformed(java.awt.event.ActionEvent evt)    {   arrayPointer = 0;   setFields(arrayPointer);       }     });//End of the buttonReset Action public void setFields(int position) {     textFieldName.setText(DataClassArray[position].getName());     textFieldAddress.setText(DataClassArray[position].getAddress());     textFieldCity.setText(DataClassArray[position].getCity());     textFieldState.setText(DataClassArray[position].getState());     textFieldZip.setText(DataClassArray[position].getZip()); }      public void shutDown()   {     int returnVal=JOptionPane.showConfirmDialog(this, "Are you sure you want to quit?");     if(returnVal==JOptionPane.YES_OPTION) {       System.exit(0);     }   }   public static void main(String args[])   { hello a2 = new hello ("Swing Application");     a2.setSize(400,350);     a2.setVisible(true);   } } class DataClass{   String name, address, city, state, zipCode;   DataClass(String name, String address, String city, String state, String zipCode)   { this.name = name;     this.address = address;     this.city = city;     this.state = state;     this.zipCode = zipCode;   }     String getName()   {   return this.name;   }   String getAddress()   {   return this.address;   }   String getCity()   {   return this.city;   }   String getState()   {   return this.state;   }   String getZip()   {   return this.zipCode;   } }

rajmani · Dec 16, 2009 11:12 PM · 321 views

2 Replies

I have pasted the solution to your Assignment_2_2 over here: http://gist.github.com/258559

HowardRoark · Dec 17, 2009 12:03 AM

import javax.swing.*; import java.awt.*; import java.awt.event.*; class hello extends JFrame{   private JButton buttonPrevious=new JButton("Prev");   private JButton buttonReset=new JButton("Reset");   private JButton buttonNext=new JButton("Next");   private JLabel labelHeader=new JLabel("Database Browser",JLabel.CENTER);   private JLabel labelName=new JLabel("Name");   private JLabel labelAddress=new JLabel("Address");   private JLabel labelCity=new JLabel("City");   private JLabel labelState=new JLabel("State");   private JLabel labelZip=new JLabel("Zip");   private JTextField textFieldName=new JTextField();   private JTextField textFieldAddress=new JTextField();   private JTextField textFieldCity=new JTextField();   private JTextField textFieldState=new JTextField();   private JTextField textFieldZip=new JTextField();   DataClass [] DataClassArray = {                             new DataClass("Fred", "Wayne", "101 Here", "NE", "55551"),                             new DataClass("Goerge", "Thomas", "102 There", "ME", "55552"),                             new DataClass("Mike", "Johnson", "103 No Where", "OK", "55553") };   int arrayPointer=0;   public hello(String title){     super(title);     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);     JPanel cp=(JPanel)getContentPane();     labelHeader.setFont(new Font("Verdana",Font.BOLD,24));     labelHeader.setBounds(40,10,300,50);     buttonPrevious.setBounds(30,250,80,25);     buttonReset.setBounds(150,250,80,25);     buttonNext.setBounds(270,250,80,25);     labelName.setBounds(10,80,80,25);     labelAddress.setBounds(10,110,80,25);     labelCity.setBounds(10,140,80,25);     labelState.setBounds(10,170,80,25);     labelZip.setBounds(10,200,80,25);     textFieldName.setBounds(120,80,250,25);     textFieldAddress.setBounds(120,110,250,25);     textFieldCity.setBounds(120,140,250,25);     textFieldState.setBounds(120,170,250,25);     textFieldZip.setBounds(120,200,250,25);     cp.setLayout(null);     cp.add(labelHeader);     cp.add(buttonPrevious);     cp.add(buttonReset);     cp.add(buttonNext);     cp.add(labelName);     cp.add(textFieldName);     cp.add(labelAddress);     cp.add(textFieldAddress);     cp.add(labelCity);     cp.add(textFieldCity);     cp.add(labelState);     cp.add(textFieldState);     cp.add(labelZip);     cp.add(textFieldZip);     addWindowListener(new java.awt.event.WindowAdapter() {       public void windowClosing(java.awt.event.WindowEvent evt) {         shutDown();       }     });    buttonPrevious.addActionListener(new java.awt.event.ActionListener()  {   //if the Previous button is pressed, show the Previous value in the       public void actionPerformed(java.awt.event.ActionEvent evt)    {         if(arrayPointer > 0)   {           --arrayPointer;     setFields(arrayPointer);         }       }     });//End of the buttonPrevious Acction  //Event for the Next Button.  buttonNext.addActionListener(new java.awt.event.ActionListener()  {   //if the Next button is pressed, show the Next value in the DataClassArray       public void actionPerformed(java.awt.event.ActionEvent evt)    {         if (arrayPointer >= 0 && arrayPointer < 2)   {    ++arrayPointer;    setFields(arrayPointer);   }       }     });//End of the buttonNext Action.  //Event for the Reset Button.  buttonReset.addActionListener(new java.awt.event.ActionListener()  {       //if the reset button is pressed, show the first value in the    public void actionPerformed(java.awt.event.ActionEvent evt)    {   arrayPointer = 0;   setFields(arrayPointer);       }     });//End of the buttonReset Action   } public void setFields(int position) {     textFieldName.setText(DataClassArray[position].getName());     textFieldAddress.setText(DataClassArray[position].getAddress());     textFieldCity.setText(DataClassArray[position].getCity());     textFieldState.setText(DataClassArray[position].getState());     textFieldZip.setText(DataClassArray[position].getZip()); }   public void shutDown()   {     int returnVal=JOptionPane.showConfirmDialog(this, "Are you sure you want to quit?");     if(returnVal==JOptionPane.YES_OPTION) {       System.exit(0);     }   }   public static void main(String args[])   { hello a2= new hello ("Swing Application");     a2.setSize(400,350);     a2.setVisible(true);   } } class DataClass{   String name, address, city, state, zipCode;   DataClass(String name, String address, String city, String state, String zipCode)   { this.name = name;     this.address = address;     this.city = city;     this.state = state;     this.zipCode = zipCode;   }   String getName()   {   return this.name;   }   String getAddress()   {   return this.address;   }   String getCity()   {   return this.city;   }   String getState()   {   return this.state;   }   String getZip()   {   return this.zipCode;   } }

javap · Dec 17, 2009 12:18 AM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion