Results 1 to 1 of 1
Thread: Add string
- 02-07-2008, 09:08 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
Add string
I'm trying to write myself a code in which I can store names and then create a JList so that I can scroll through these names and then have a JMenuItem in the Contacts menu I have used to add a new name to the list. I have written the following that works for scrolling through the names as well as exiting the system but I think my poor programming has stopped me from being able to add a code so that new people can be "Added" Could someone please help because I'm stumped and it's starting to annoy me :confused:
//
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ListTest extends JFrame {
private JList nameList;
private Container container;
private final String Names [] = {"Morten Gamst", "Freddie Fred", "Steve Ridby"};
//
public ListTest(){
super ("List Test");
//
JMenu fileMenu = new JMenu ("File");
fileMenu.setMnemonic ('F');
JMenu contactMenu = new JMenu ("Contacts");
fileMenu.setMnemonic ('C');
//
container = getContentPane ();
container.setLayout (new GridLayout());
//
nameList = new JList (Names);
//
nameList.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
//
container.add (new JScrollPane (nameList));
JMenuItem exitItem = new JMenuItem ("Exit");
exitItem.setMnemonic ('x');
fileMenu.add (exitItem);
exitItem.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent event)
{
System.exit (0);
}
}
);
JMenuItem addItem = new JMenuItem ("Add Contact");
addItem.setMnemonic ('a');
contactMenu.add(addItem);
JMenuBar bar = new JMenuBar ();
setJMenuBar (bar);
bar.add (fileMenu);
bar.add (contactMenu);
setSize (250,200);
setVisible (true);
}//
public static void main (String args[])
{
ListTest application = new ListTest();
application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
}
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
String vs new String
By bugger in forum New To JavaReplies: 20Last Post: 11-26-2007, 12:21 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Help with insertName(String name) and deleteName(String name)
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks