The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Getting a GUI to work

Posted by Eric on November 26, 2001 at 10:56 PM

Dear Java Answers Forum,

I am trying to fix my java gui code and am looking for help. The buttons seem to be working, I am trying to create a database so that I can add and edit items. How can I get my GUI to function correctly? any suggestions or different ways to write this code. can you send them to emanfl@hotmail.com or post here

Thanks,

Eric

* see code below
Compile both java files and run Pim.

(pim.java)

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class Pim extends javax.swing.JFrame implements ActionListener, ListSelectionListener
{

private javax.swing.JButton jbuttonDescrEdit = null;
private javax.swing.JButton jbuttonImageAdd = null;
private javax.swing.JButton jbuttonImageDelete = null;
private javax.swing.JButton jbuttonImageView = null;
private javax.swing.JPanel jframeContentPane = null;
private javax.swing.JLabel jlabelCondition = null;
private javax.swing.JLabel jlabelDate = null;
private javax.swing.JLabel jlabelDescription = null;
private javax.swing.JLabel jlabelImage = null;
private javax.swing.JLabel jlabelItem = null;
private javax.swing.JLabel jlabelLocation = null;
private javax.swing.JLabel jlabelNumber = null;
private javax.swing.JLabel jlabelValue = null;
private static javax.swing.JList jlistItemList = null;
private javax.swing.JMenu jmenuFile = null;
private javax.swing.JRadioButton jradiobuttonFair = null;
private javax.swing.JRadioButton jradiobuttonGood = null;
private javax.swing.JRadioButton jradiobuttonPoor = null;
private javax.swing.JScrollPane jscrollpaneItems = null;
private javax.swing.JSeparator JSeparator1 = null;
private javax.swing.JTextField jtextfieldItem = null;
private javax.swing.JMenuBar pimJMenuBar = null;
private javax.swing.JMenu jmenuTools = null;
private javax.swing.JSeparator JSeparator2 = null;
private javax.swing.JSeparator JSeparator3 = null;
private javax.swing.JLabel jlabelItemList = null;
private javax.swing.JButton jbuttonDescrView = null;
private static javax.swing.JMenuItem jemuitemToolsAdd = null;
private static javax.swing.JMenuItem jmenuitemFileExit = null;
private static javax.swing.JMenuItem jmenuitemFileNew = null;
private static javax.swing.JMenuItem jmenuitemToolsDelete = null;
private static javax.swing.JMenuItem jmenuitemToolsUpdate = null;
private javax.swing.JTextField jtextfieldDate = null;
private javax.swing.JTextField jtextfieldLocation = null;
private javax.swing.JTextField jtextfieldNumber = null;
private static Vector vectorlist1= null;
public static Pim aPim;
public static Vector vectorlist2 = null;
public static Itemobject itemobjectname;
private javax.swing.JTextField jtextfieldValue = null;
/*
*
* Function: Pim
*
* Description: 1. constructor that takes no input parameters,
* calls JFrame constructor passing no parameters, and lastly,
* calls the initialize function down below to create the

* JFrame and all its components.
*
*
*
*/
public Pim() {
super();
initialize();
}
/*
*
* Function: Pim
*
* Description: 1. constructor that calls JFrame constructor passing a title
for
* the Jframe as a parameter.
*
*
*
*/
public Pim(String title) {
super(title);
}
/*
*
* Function: getjbuttonDescrEdit
*
* Description: 1. create instance of JButton, set text displayed on button,
and
* set bounds for button.
*
*
*********************************************************************************/
public void valueChanged(ListSelectionEvent e)
{
}

//*************************************************************************
private javax.swing.JButton getjbuttonDescrEdit() {
if (jbuttonDescrEdit == null) {
try {
jbuttonDescrEdit = new javax.swing.JButton();
jbuttonDescrEdit.setName("jbuttonDescrEdit");
jbuttonDescrEdit.setText("Edit");
jbuttonDescrEdit.setBounds(352, 103, 55, 25);
jbuttonDescrEdit.setActionCommand("DescrEdit");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jbuttonDescrEdit;
}
/*
*
* Function: getjbuttonDescrView
*
* Description: 1. create instance of JButton, set text displayed on button,
and
* set bounds for button.
*
*
*/
private javax.swing.JButton getjbuttonDescrView() {
if (jbuttonDescrView == null) {
try {
jbuttonDescrView = new javax.swing.JButton();
jbuttonDescrView.setName("jbuttonDescrView");
jbuttonDescrView.setText("View");
jbuttonDescrView.setBounds(267, 103, 68, 25);
jbuttonDescrView.setActionCommand("DescrView");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jbuttonDescrView;
}
/**
* Return the jbuttonImageAdd property value.
* @return javax.swing.JButton
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getjbuttonImageAdd() {
if (jbuttonImageAdd == null) {
try {
jbuttonImageAdd = new javax.swing.JButton();
jbuttonImageAdd.setName("jbuttonImageAdd");
jbuttonImageAdd.setText("Add");
jbuttonImageAdd.setBounds(266, 257, 80, 25);
jbuttonImageAdd.setActionCommand("ImageAdd");
// user code begin {1}
// user code end
} catch (java.lang.Throwable Exc) {
// user code begin {2}
// user code end
handleException(Exc);
}
}
return jbuttonImageAdd;
}
/*
*
* Function: getjbuttonImageDelete
*
* Description: 1. create instance of JButton, set text displayed on button,
and
* set bounds for button.
*
*
*/
private javax.swing.JButton getjbuttonImageDelete() {
if (jbuttonImageDelete == null) {
try {
jbuttonImageDelete = new javax.swing.JButton();
jbuttonImageDelete.setName("jbuttonImageDelete");
jbuttonImageDelete.setText("Delete");
jbuttonImageDelete.setBounds(363, 257, 74, 25);
jbuttonImageDelete.setActionCommand("ImageDelete");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jbuttonImageDelete;
}
/*
*
* Function: getjbuttonImageView
*
* Description: 1. create instance of JButton, set text displayed on button,
and
* set bounds for button.
*
*
*/
private javax.swing.JButton getjbuttonImageView() {
if (jbuttonImageView == null) {
try {
jbuttonImageView = new javax.swing.JButton();
jbuttonImageView.setName("jbuttonImageView");
jbuttonImageView.setText("View");
jbuttonImageView.setBounds(449, 257, 62, 25);
jbuttonImageView.setActionCommand("ImageView");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jbuttonImageView;
}
/*
*
* Function: getjmenuitemToolsAdd
*
* Description: 1. create instance of JMenuItem, set text displayed in item,
and
* set ActionCommand string that will be returned when item
is selected.
*
*
*/
private javax.swing.JMenuItem getjemuitemToolsAdd() {
if (jemuitemToolsAdd == null) {
try {
jemuitemToolsAdd = new javax.swing.JMenuItem();
jemuitemToolsAdd.setName("jemuitemToolsAdd");
jemuitemToolsAdd.setText("Add");
jemuitemToolsAdd.setActionCommand("ToolsAdd");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jemuitemToolsAdd;
}
/*
*
* Function: getjframeContentPane
*
* Description: 1. create instance of JPanel,
* 2. get the contentpane within JPanel,
* 3. set the layout mgr to "null"
* 4. add all buttons, text fields, labels, and the menubar
to the JPanel
* 5. catch any exception from methods that are called.
*
*
*/
private javax.swing.JPanel getjframeContentPane() {
if (jframeContentPane == null) {
try {
jframeContentPane = new javax.swing.JPanel();
jframeContentPane.setName("jframeContentPane");
jframeContentPane.setLayout(null);
getjframeContentPane().add(getjscrollpaneItems(), getjscrollpaneItems().getName());
getjframeContentPane().add(getjlabelItem(), getjlabelItem().getName());
getjframeContentPane().add(getjtextfieldItem(), getjtextfieldItem().getName());
getjframeContentPane().add(getjlabelNumber(), getjlabelNumber().getName());
getjframeContentPane().add(getjtextfieldNumber(), getjtextfieldNumber().getName());
getjframeContentPane().add(getjlabelDescription(), getjlabelDescription().getName());
getjframeContentPane().add(getjlabelValue(), getjlabelValue().getName());
getjframeContentPane().add(getjtextfieldValue(), getjtextfieldValue().getName());
getjframeContentPane().add(getjlabelLocation(), getjlabelLocation().getName());
getjframeContentPane().add(getjtextfieldLocation(), getjtextfieldLocation().getName());
getjframeContentPane().add(getjbuttonDescrView(), getjbuttonDescrView().getName());
getjframeContentPane().add(getjbuttonDescrEdit(), getjbuttonDescrEdit().getName());
getjframeContentPane().add(getjtextfieldDate(), getjtextfieldDate().getName());
getjframeContentPane().add(getjlabelDate(), getjlabelDate().getName());
getjframeContentPane().add(getjlabelCondition(), getjlabelCondition().getName());
getjframeContentPane().add(getjradiobuttonGood(), getjradiobuttonGood().getName());
getjframeContentPane().add(getjradiobuttonFair(), getjradiobuttonFair().getName());
getjframeContentPane().add(getjradiobuttonPoor(), getjradiobuttonPoor().getName());
getjframeContentPane().add(getjbuttonImageView(), getjbuttonImageView().getName());
getjframeContentPane().add(getjbuttonImageAdd(), getjbuttonImageAdd().getName());
getjframeContentPane().add(getjlabelImage(), getjlabelImage().getName());
getjframeContentPane().add(getjbuttonImageDelete(), getjbuttonImageDelete().getName());
getjframeContentPane().add(getjlabelItemList(), getjlabelItemList().getName());

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jframeContentPane;
}
/*
*
* Function: getjlabelCondition
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelCondition() {
if (jlabelCondition == null) {
try {
jlabelCondition = new javax.swing.JLabel();
jlabelCondition.setName("jlabelCondition");
jlabelCondition.setText("Condition");
jlabelCondition.setBounds(180, 224, 59, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelCondition;
}
/*
*
* Function: getjlabelDate
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/

private javax.swing.JLabel getjlabelDate() {
if (jlabelDate == null) {
try {
jlabelDate = new javax.swing.JLabel();
jlabelDate.setName("jlabelDate");
jlabelDate.setText("Date of Purchase");
jlabelDate.setBounds(179, 193, 109, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelDate;
}
/*
*
* Function: getjlabelDescription
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelDescription() {
if (jlabelDescription == null) {
try {

jlabelDescription = new javax.swing.JLabel();
jlabelDescription.setName("jlabelDescription");
jlabelDescription.setText("Description");
jlabelDescription.setBounds(180, 108, 75, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelDescription;
}
/*
*
* Function: getjlabelImage
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelImage() {
if (jlabelImage == null) {
try {
jlabelImage = new javax.swing.JLabel();
jlabelImage.setName("jlabelImage");
jlabelImage.setText("Image");
jlabelImage.setBounds(181, 261, 59, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelImage;
}
/*
*
* Function: getjlabelItem
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelItem() {
if (jlabelItem == null) {
try {
jlabelItem = new javax.swing.JLabel();
jlabelItem.setName("jlabelItem");
jlabelItem.setText("Item");
jlabelItem.setBounds(180, 53, 37, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelItem;
}
/*
*
* Function: getjlabelItemList
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelItemList() {
if (jlabelItemList == null) {
try {
jlabelItemList = new javax.swing.JLabel();
jlabelItemList.setName("jlabelItemList");
jlabelItemList.setText("Item List");
jlabelItemList.setBounds(12, 21, 60, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelItemList;
}
/*
*
* Function: getjlabelLocation
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelLocation() {
if (jlabelLocation == null) {
try {
jlabelLocation = new javax.swing.JLabel();
jlabelLocation.setName("jlabelLocation");
jlabelLocation.setText("Location");
jlabelLocation.setBounds(179, 165, 58, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelLocation;
}
/*
*
* Function: getjlabelNumber
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/

private javax.swing.JLabel getjlabelNumber() {
if (jlabelNumber == null) {
try {
jlabelNumber = new javax.swing.JLabel();
jlabelNumber.setName("jlabelNumber");
jlabelNumber.setText("Number of");
jlabelNumber.setBounds(180, 77, 66, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelNumber;
}
/*
*
* Function: getjlabelValue
*
* Description: 1. create instance of JLabel, set bounds on object, and
set text shown in
* label.
*
*/
private javax.swing.JLabel getjlabelValue() {
if (jlabelValue == null) {
try {
jlabelValue = new javax.swing.JLabel();
jlabelValue.setName("jlabelValue");
jlabelValue.setText("Value $");
jlabelValue.setBounds(180, 137, 52, 14);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlabelValue;
}
/*
*
* Function: getjlistItemList
*
* Description: 1. create instance of JList
* 2. set bounds on object, allow container in which JList
will be
* to determine dimensions of JList.
*
*
*/

private javax.swing.JList getjlistItemList() {
if (jlistItemList == null) {
try {
vectorlist1= new Vector();

//Itemobject itemobjectname = new Itemobject ();
//Itemobject itemobjectdesc = new Itemobject ();
//Itemobject itemobjectint = new Itemobject ();
jlistItemList = new javax.swing.JList(vectorlist1);
jlistItemList.setName("jlistItemList");
jlistItemList.setBounds(0, 0, 160, 176);


} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jlistItemList;
}
/*
*
* Function: getjmenuFile
*
* Description: 1. create instance of JMenu,
* 2. add JMenuItems to menu with a separator between items.

*
*
*/
private javax.swing.JMenu getjmenuFile() {
if (jmenuFile == null) {
try {
jmenuFile = new javax.swing.JMenu();
jmenuFile.setName("jmenuFile");
jmenuFile.setText("File");
jmenuFile.setActionCommand("File");
jmenuFile.add(getjmenuitemFileNew());
jmenuFile.add(getJSeparator1());
jmenuFile.add(getjmenuitemFileExit());

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuFile;
}
/*
*
* Function: getjmenuitemExit
*
* Description: 1. create instance of JMenuItem,
* 2. set string displayed in menu item.
*
*
*/
private javax.swing.JMenuItem getjmenuitemFileExit() {
if (jmenuitemFileExit == null) {
try {
jmenuitemFileExit = new javax.swing.JMenuItem();
jmenuitemFileExit.setName("jmenuitemFileExit");
jmenuitemFileExit.setText("Exit");
jmenuitemFileExit.setActionCommand("FileExit");
//jmenuitemFileExit.addActionListener(aPim);
} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuitemFileExit;
}
/*
*
* Function: getjmenuitemFileNew
*
* Description: 1. create instance of JMenuItem,
* 2. set text displayed in menu item.
*
*
*/
private javax.swing.JMenuItem getjmenuitemFileNew() {
if (jmenuitemFileNew == null) {
try {
jmenuitemFileNew = new javax.swing.JMenuItem();
jmenuitemFileNew.setName("jmenuitemFileNew");
jmenuitemFileNew.setText("New");
jmenuitemFileNew.setActionCommand("FileNew");
//jmenuitemFileNew.addActionListener ();
} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuitemFileNew;
}
/*
*
* Function: getjmenuitemToolsDelete
*
* Description: 1. create instance of JMenuItem,
* 2. set text displayed in menu item.
*
*
*/
private javax.swing.JMenuItem getjmenuitemToolsDelete() {
if (jmenuitemToolsDelete == null) {
try {
jmenuitemToolsDelete = new javax.swing.JMenuItem();
jmenuitemToolsDelete.setName("jmenuitemToolsDelete");
jmenuitemToolsDelete.setText("Delete");
jmenuitemToolsDelete.setActionCommand("ToolsDelete");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuitemToolsDelete;
}
/*
*
* Function: getjmenuitemToolsUpdate
*
* Description: 1. create instance of JMenuItem,
* 2. set text displayed in menu item.
*
*
*/
private javax.swing.JMenuItem getjmenuitemToolsUpdate() {
if (jmenuitemToolsUpdate == null) {
try {
jmenuitemToolsUpdate = new javax.swing.JMenuItem();
jmenuitemToolsUpdate.setName("jmenuitemToolsUpdate");
jmenuitemToolsUpdate.setText("Update");
jmenuitemToolsUpdate.setActionCommand("ToolsUpdate");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuitemToolsUpdate;
}
/*
*
* Function: getjmenuTools
*
* Description: 1. create instance of JMenu,
* 2. add JMenuItems to menu with a separator between items.

*
*
*/
private javax.swing.JMenu getjmenuTools() {
if (jmenuTools == null) {
try {
jmenuTools = new javax.swing.JMenu();
jmenuTools.setName("jmenuTools");
jmenuTools.setText("Tools");
jmenuTools.setActionCommand("Tools");
jmenuTools.add(getjemuitemToolsAdd());
jmenuTools.add(getJSeparator2());
jmenuTools.add(getjmenuitemToolsUpdate());
jmenuTools.add(getJSeparator3());
jmenuTools.add(getjmenuitemToolsDelete());

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jmenuTools;
}
/*
*
* Function: getjradiobuttonFair
*
* Description: 1. create instance of JRadioButton, set text displayed on
button, and
* set bounds for button.
*
*
*/
private javax.swing.JRadioButton getjradiobuttonFair() {
if (jradiobuttonFair == null) {
try {
jradiobuttonFair = new javax.swing.JRadioButton();
jradiobuttonFair.setName("jradiobuttonFair");
jradiobuttonFair.setText("Fair");
jradiobuttonFair.setBounds(338, 221, 42, 22);
jradiobuttonFair.setActionCommand("Fair");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jradiobuttonFair;
}
/*
*
* Function: getjradiobuttonGood
*
* Description: 1. create instance of JRadioButton, set text displayed on
button, and
* set bounds for button.
*
*
*/

private javax.swing.JRadioButton getjradiobuttonGood() {
if (jradiobuttonGood == null) {
try {
jradiobuttonGood = new javax.swing.JRadioButton();
jradiobuttonGood.setName("jradiobuttonGood");
jradiobuttonGood.setText("Good");
jradiobuttonGood.setBounds(267, 221, 53, 22);
jradiobuttonGood.setActionCommand("Good");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jradiobuttonGood;
}
/*
*
* Function: getjradiobuttonPoor
*
* Description: 1. create instance of JRadioButton, set text displayed on
button, and
* set bounds for button.
*
*
*/
private javax.swing.JRadioButton getjradiobuttonPoor() {
if (jradiobuttonPoor == null) {
try {
jradiobuttonPoor = new javax.swing.JRadioButton();
jradiobuttonPoor.setName("jradiobuttonPoor");
jradiobuttonPoor.setText("Poor");
jradiobuttonPoor.setBounds(396, 221, 53, 22);
jradiobuttonPoor.setActionCommand("Poor");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jradiobuttonPoor;
}
/*
*
* Function: getjscrollpaneItems
*
* Description: 1. create instance of jscrollpane, set bounds on object,
and set the
* jscrollList inside of jscrollpane.
*
*
*/

private javax.swing.JScrollPane getjscrollpaneItems() {
if (jscrollpaneItems == null) {
try {
jscrollpaneItems = new javax.swing.JScrollPane();
jscrollpaneItems.setName("jscrollpaneItems");
jscrollpaneItems.setBounds(14, 47, 140, 264);
getjscrollpaneItems().setViewportView(getjlistItemList());

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jscrollpaneItems;
}
/*
*
* Function: getJSeparator1
*
* Description: 1. create separator for menu item list.
*
*
*/
private javax.swing.JSeparator getJSeparator1() {
if (JSeparator1 == null) {
try {
JSeparator1 = new javax.swing.JSeparator();
JSeparator1.setName("JSeparator1");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return JSeparator1;
}
/*
*
* Function: getJSeparator2
*
* Description: 1. create separator for menu item list.
*
*
*/
private javax.swing.JSeparator getJSeparator2() {
if (JSeparator2 == null) {
try {
JSeparator2 = new javax.swing.JSeparator();
JSeparator2.setName("JSeparator2");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return JSeparator2;
}
/*
*
* Function: getJSeparator3
*
* Description: 1. create separator for menu item list.
*
*
*/
private javax.swing.JSeparator getJSeparator3() {
if (JSeparator3 == null) {
try {
JSeparator3 = new javax.swing.JSeparator();
JSeparator3.setName("JSeparator3");

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return JSeparator3;
}
/*
*
* Function: getjtextfieldDate
*
* Description: 1. create instance of JTextField
* 2. set bounds on textfield
*
*
*/
private javax.swing.JTextField getjtextfieldDate() {
if (jtextfieldDate == null) {
try {
jtextfieldDate = new javax.swing.JTextField();
jtextfieldDate.setName("jtextfieldDate");
jtextfieldDate.setBounds(397, 188, 114, 20);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jtextfieldDate;
}
/*
*
* Function: getjtextfieldItem
*
* Description: 1. create instance of JTextField
* 2. set bounds on textfield
*
*
*/private javax.swing.JTextField getjtextfieldItem() {
if (jtextfieldItem == null) {
try {
jtextfieldItem = new javax.swing.JTextField();
jtextfieldItem.setName("jtextfieldItem");
jtextfieldItem.setBounds(268, 50, 243, 20);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jtextfieldItem;
}
/*
*
* Function: getjtextfieldLocation
*
* Description: 1. create instance of JTextField
* 2. set bounds on textfield
*
*
*/private javax.swing.JTextField getjtextfieldLocation() {
if (jtextfieldLocation == null) {
try {
jtextfieldLocation = new javax.swing.JTextField();
jtextfieldLocation.setName("jtextfieldLocation");
jtextfieldLocation.setBounds(268, 160, 243, 20);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jtextfieldLocation;
}
/*
*
* Function: getjtextfieldNumber
*
* Description: 1. create instance of JTextField
* 2. set bounds on textfield
*
*
*/private javax.swing.JTextField getjtextfieldNumber() {
if (jtextfieldNumber == null) {
try {
jtextfieldNumber = new javax.swing.JTextField();
jtextfieldNumber.setName("jtextfieldNumber");
jtextfieldNumber.setBounds(268, 76, 243, 20);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jtextfieldNumber;
}
/*
*
* Function: getjtextfieldValue
*
* Description: 1. create instance of JTextField
* 2. set bounds on textfield
*
*
*/private javax.swing.JTextField getjtextfieldValue() {
if (jtextfieldValue == null) {
try {
jtextfieldValue = new javax.swing.JTextField();
jtextfieldValue.setName("jtextfieldValue");
jtextfieldValue.setBounds(268, 134, 243, 20);

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return jtextfieldValue;
}
/*
*
* Function: getpimMenuBar
*
* Description: 1. create instance of JMenuBar
* 2. add File and Tool Menues to menu bar
*
*
*/
private javax.swing.JMenuBar getpimJMenuBar() {
if (pimJMenuBar == null) {
try {
pimJMenuBar = new javax.swing.JMenuBar();
pimJMenuBar.setName("pimJMenuBar");
pimJMenuBar.add(getjmenuFile());
pimJMenuBar.add(getjmenuTools());

} catch (java.lang.Throwable Exc) {

handleException(Exc);
}
}
return pimJMenuBar;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(java.lang.Throwable exception) {

/* Uncomment the following lines to print uncaught exceptions to stdout
*/
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/*
*
* Function: Initialize
*
* Description: 1. initializes the jframe with a title.
* 2. set the default window close operation to close the jframe
window.
* 3. sets the size of the jframe that will be displayed.
* 4. sets the menubar into the JFrame.
* 5. sets the JFrame contentpane to created contentpane.
* 6. Catch exception from any method call made earlier.
*/

private void initialize() {
try {

setName("Pim");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Personal Inventory Manager");
setSize(529, 361);
setJMenuBar(getpimJMenuBar());
setContentPane(getjframeContentPane());
} catch (java.lang.Throwable Exc) {
handleException(Exc);
}

}
/*
*
* Function: Main
*
* Description: 1. Creates an instance PIM object.
* 2. Adds a window for the Jframe to detect window close.
* 3. Shows the Jframe to user.
* 4. Creates an instance of awt.Insets to position objects
into Jframe.
* These are invisible objects which take space in the GUI.
Allows
* user to center objects in frame.
* 5. Show the insets.
* 6. Catch exception from any method call made earlier.
*/
public static void main(java.lang.String[] args) {
try {
Pim aPim;
aPim = new Pim();

aPim.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e)
{
System.exit(0);
};

});

jmenuitemFileNew.addActionListener(aPim);
jmenuitemFileExit.addActionListener (aPim);

aPim.show();
java.awt.Insets insets = aPim.getInsets();
aPim.setSize(529, 361);//aPim.getWidth() + insets.left + insets.right,
aPim.getHeight() + insets.top + insets.bottom);
aPim.setVisible(true);

} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JFrame");
exception.printStackTrace(System.out);
}


}
public void actionPerformed (ActionEvent w)
{
Itemobject itemobjectname = new Itemobject ();
//Itemobject itemobjectdesc= new Itemobject();
String output3="", output2="", output1="";
if("FileNew".equals(w.getActionCommand ())){
output1=jtextfieldItem.getText();
//vectorlist1.setElementAt (jtextfieldItem.getText (),jlistItemList.getSelectedIndex
());
vectorlist1.addElement(output1);
//test
itemobjectname.setitemname (output1);
jlistItemList.setListData(vectorlist1);
//vectorlist2 .addElement (itemobjectname);
output2=jtextfieldValue.getText();

itemobjectname.setitemdesc(output2);
//vectorlist2 .addElement ( );
//JOptionPane.showInputDialog (vectorlist2);

//JOptionPane.showMessageDialog (null,vectorlist2,"",JOptionPane.INFORMATION_MESSAGE
);

}
if(jmenuitemFileExit.equals (w.getActionCommand ()))
{
JOptionPane.showMessageDialog (null,itemobjectname.setitemname(output1),"",JOptionPane.INFORMATION_MESSAGE
);

}
}
}


(Itemobject.java)

import javax.swing.*;
import java.awt.*;
import javax.swing.event.* ;
import java.util.*;

public class Itemobject extends Object {
public String Itemname;
public String Itemdesc;
private int radiobuttontest;
public Vector vectorlist2 = null;
public Itemobject itemobjectname2=null;
public Itemobject ()
{
itemobjectname2 = new Itemobject ();
;
//vectorlist2.addElement (itemobjectname);
//JOptionPane.showInputDialog (vectorlist2);
}

// vectorlist2.addElement (radiobuttontest);
//vectorlist2.addElement (Itemdesc);
//vectorlist2.addElement (Itemname);


public String setitemname(String Itemname)
{
//vectorlist2.addElement (Itemname);
//JOptionPane.showInputDialog (vectorlist2);
return (Itemname);
}

public String additemtovector(Itemobject itemobjectname)
{ vectorlist2=new Vector() ;
itemobjectname.equals (vectorlist2);
//vectorlist2. (itemobjectname2);
System.out.println (vectorlist2);
return (null);
}
public String setitemdesc(String Itemdesc)
{//vectorlist2.addElement (Itemdesc);
return (Itemdesc);

} public int setradiobuttontest()

{

return (radiobuttontest);
}

}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us