Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 06:14 AM
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
Help with program coding
Hi, I am having problems with a program i am making the program coding is

Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.ArrayList; import java.util.List; public class Contacts implements ActionListener { JFrame contactsFrame; JPanel contactsPanel; JTextField name, lname, phonenum; JLabel names, lnames, phonenums; JButton next, back, add, edit, save; List data = new ArrayList(); int a=0, b=0; public Contacts() { //Create and set up the window. contactsFrame = new JFrame("Contacts Manager Program"); contactsFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contactsFrame.setSize(3020, 40); //Create and set up the panel. contactsPanel = new JPanel(new GridLayout(5, 2)); //Add the widgets. addWidgets(); //Add the panel to the window. contactsFrame.getContentPane().add(contactsPanel, BorderLayout.CENTER); //Display the window. contactsFrame.pack(); contactsFrame.setVisible(true); } private void addWidgets() { //Create widgets. name = new JTextField(data.get(0)); lname = new JTextField(data.get(1)); phonenum = new JTextField(data.get(2)); names = new JLabel("Name:"); lnames = new JLabel("Last Name:"); phonenums = new JLabel("Phone Number:"); next = new JButton("Next"); back = new JButton("Back"); add = new JButton("Add new Contact"); edit = new JButton("Save Changes"); //Listen to events from the Convert button. next.addActionListener(this); back.addActionListener(this); add.addActionListener(this); //Add the widgets to the container. contactsPanel.add(names); contactsPanel.add(name); contactsPanel.add(lnames); contactsPanel.add(lname); contactsPanel.add(phonenums); contactsPanel.add(phonenum); contactsPanel.add(back); contactsPanel.add(next); contactsPanel.add(add); contactsPanel.add(edit); } public void actionPerformed(ActionEvent event) { if(event.getSource()==add) { data.add(name.getText()); data.add(lname.getText()); data.add(phonenum.getText()); b=b+3; } if(event.getSource()==next) { if (a!=b) { a=a+3; } name.setText(data.get(a)); lname.setText(data.get(a+1)); phonenum.setText(data.get(a+2)); } if(event.getSource()==back) { if(a!=0){ a=a-3; } name.setText(data.get(a)); lname.setText(data.get(a+1)); phonenum.setText(data.get(a+2)); } //if(event.getSource()==edit) { //data[a]=name.getText(); //data[a+1]=lname.getText(); //data[a+2]=phonenum.getText(); //data2[a]=name.getText(); //data2[a+1]=lname.getText(); //data2[a+2]=phonenum.getText(); //} } private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); Contacts converter = new Contacts(); } public void main(String[] args) throws Exception { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. read(); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } public void write() throws Exception { } public void read() throws Exception { data = new ArrayList(); BufferedReader reader= new BufferedReader(new FileReader("foo.txt")); String textline = null; while((textline = reader.readLine()) != null){ data.add(textline); b++; } reader.close(); } }
The problems i am having with are
Code:
E:\Contacts.java:39: cannot resolve symbol symbol : constructor JTextField (java.lang.Object) location: class javax.swing.JTextField name = new JTextField(data.get(0)); ^ E:\Contacts.java:40: cannot resolve symbol symbol : constructor JTextField (java.lang.Object) location: class javax.swing.JTextField lname = new JTextField(data.get(1)); ^ E:\Contacts.java:41: cannot resolve symbol symbol : constructor JTextField (java.lang.Object) location: class javax.swing.JTextField phonenum = new JTextField(data.get(2)); ^ E:\Contacts.java:80: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) name.setText(data.get(a)); ^ E:\Contacts.java:81: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) lname.setText(data.get(a+1)); ^ E:\Contacts.java:82: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) phonenum.setText(data.get(a+2)); ^ E:\Contacts.java:88: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) name.setText(data.get(a)); ^ E:\Contacts.java:89: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) lname.setText(data.get(a+1)); ^ E:\Contacts.java:90: setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (java.lang.Object) phonenum.setText(data.get(a+2)); ^
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 08:16 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Quote:
List data = new ArrayList();
// What does get return?
System.out.println("data.get(0) = " + data.get(0).getClass().getName());
Java has no idea what is in this list. The programmer should know but the jvm cannot know. So you must cast the object that the get method returns. If there are Strings in the list then
Code:
String s = (String)list.get(0);
This is acceptable as the argument for the JTextComponent.setText method.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding an FTP server in java Zucheto Networking 3 06-22-2008 05:24 AM
Help On Coding problem mandrake446 New To Java 3 12-08-2007 08:01 AM
Error in my coding one198 New To Java 2 10-13-2007 06:07 AM
Cannot solve the coding problem of my assignment elimmom New To Java 3 08-13-2007 12:33 PM
Problem in my coding one198 New To Java 9 08-09-2007 11:07 AM


All times are GMT +3. The time now is 03:55 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org