| Author |
Showing the first record by press a button
|
Jay Thomas
Greenhorn
Joined: Mar 25, 2004
Posts: 3
|
|
For some reason I'm coding the .first() incorrectly because I get a compile error. This program is going to have a lot more navigating button but I decided to start will first record button first. Can someone help please, I really appreciate your time. This is my code: // Make it easy to access packaged code. import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; /** * This class defines an applet to display store locations with four navigating * buttons, First, Previous, Next, and Last. * * Written by: Jay Thomas */ public class App extends Applet implements ActionListener, MouseListener { // These object references have broad scope so they may be used throughout // the class. private SortedMap items; // The HashMap. private Store current; // The current Item object being processed. private TextField numberFld; // For entering/displaying the store number. private TextField addressFld; // For displaying the store address. private TextField phoneFld; // For entering/displaying the store phone number. private Button bfirst; // The FIRST button. private Button bnext; // The NEXT button. private Button bprevious; // The PREVIOUS button. private Button blast; // The LAST button. private Label message; // The current message. private String savedMessage; // For saving the previous message. // This method defines initial (one-time) applet processing. public void init() { // Create the HashMap collection and load it with Item objects. SortedMap items = new TreeMap(); current = new Store(56521, "4812 State Ave. Grand Rapids, MI", "616-567-1564"); current = new Store(56548, "1882 Luvs St. Big Rapids, MI", "231-452-4525"); current = new Store(56522, "1578 Main St. Pearl, MI", "564-254-4878"); // Set the size, background color, and layout manager for the applet window. // NOTE: Because no layout manager is used, each component's size and // location must be specifically set. setSize(300, 300); setBackground(Color.lightGray); setLayout(null); // Construct and set the main applet heading. Label mainHdg = new Label("Store Phone Book"); mainHdg.setSize(250, 50); mainHdg.setAlignment(Label.CENTER); mainHdg.setFont(new Font("SansSerif", Font.BOLD, 24)); add(mainHdg); mainHdg.setLocation(25, 25); // Construct and set components for entering and displaying the store number. Label numberHdg = new Label("Store #"); numberHdg.setSize(50, 25); add(numberHdg); numberHdg.setLocation(20, 100); numberFld = new TextField(); numberFld.setSize(25, 25); add(numberFld); numberFld.setLocation(20, 125); // Construct and set components for displaying the store address. Label addressHdg = new Label("Item address"); addressHdg.setSize(70, 25); add(addressHdg); addressHdg.setLocation(70, 100); addressFld = new TextField(); addressFld.setSize(130, 25); addressFld.setEditable(false); add(addressFld); addressFld.setLocation(70, 125); // Construct and set components for entering and displaying the store phone number. Label phoneHdg = new Label("Phone"); phoneHdg.setSize(50, 25); add(phoneHdg); phoneHdg.setLocation(205, 100); phoneFld = new TextField(); phoneFld.setSize(75, 25); phoneFld.setEditable(false); add(phoneFld); phoneFld.setLocation(205, 125); // Construct and set the FIRST button. bfirst = new Button("First"); bfirst.setSize(60, 50); bfirst.addActionListener(this); add(bfirst); bfirst.setLocation(30, 175); bfirst.addMouseListener(this); // Construct and set the CHANGE button. bnext = new Button("Next"); bnext.setSize(60, 50); bnext.setEnabled(false); bnext.addActionListener(this); add(bnext); bnext.setLocation(120, 175); bnext.addMouseListener(this); // Construct and set the CANCEL button. bprevious = new Button("Previous"); bprevious.setSize(60, 50); bprevious.setEnabled(false); bprevious.addActionListener(this); add(bprevious); bprevious.setLocation(210, 175); bprevious.addMouseListener(this); // Construct and set the LAST button. blast = new Button("Last"); blast.setSize(60, 50); blast.setEnabled(false); blast.addActionListener(this); add(blast); blast.setLocation(210, 175); blast.addMouseListener(this); // Construct and set a label for displaying messages. message = new Label(""); message.setSize(250, 25); message.setAlignment(Label.CENTER); add(message); message.setLocation(25, 250); } // This method implements the abstract event handler method of the // ActionListener interface to handle ActionEvents. public void actionPerformed(ActionEvent e) { // This block handles the processing of the FIRST button. if (e.getSource().equals(bfirst)) { current = (Store) items.get(current.first()); addressFld.setText(current.getAddress()); phoneFld.setText(current.getPhone()); numberFld.setText(Integer.toString(current.getStoreNumber())); bfirst.setEnabled(false); bprevious.setEnabled(true); bnext.setEnabled(true); blast.setEnabled(true); } } public void mouseEntered(MouseEvent e) { savedMessage = message.getText(); if (e.getSource().equals(bnext)) message.setText("Proceed to the next record"); } public void mouseExited(MouseEvent e) { message.setText(savedMessage); } // Other required methods of the MouseListener interface. In this applet, // they do nothing. public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} } // This class encapsulates the attributes and methods of an Item. It is by no // means complete, but ONLY used to support the testing of the applet. class Store { // Instance variables. private int number; private String address; private String phone; // This constructor initializes the instance variables to values received // from the class client without editing. public Store(int iStoreNumber, String iAddress, String iPhone) { number = iStoreNumber; address = iAddress; phone = iPhone; } // These methods are used to set the value of their associated instance // variable. public void setNumber(int nStoreNumber) { number = nStoreNumber; } public void setAddress(String nAddress) { address = nAddress; } public void setPhone(String nPhone) { phone = nPhone; } // These methods are used to get the value of their associated instance // variable. public int getStoreNumber() { return number; } public String getAddress() { return address; } public String getPhone() { return phone; } } Thanks, -Jay
|
 |
eammon bannon
Ranch Hand
Joined: Mar 16, 2004
Posts: 140
|
|
Your class Store has no first() method. So when you try to do this: You are calling a non-existant method.
|
 |
Jay Thomas
Greenhorn
Joined: Mar 25, 2004
Posts: 3
|
|
How would I go abouts and making it possible for the Store Information to show by using .first()? I'm sorry it's just getting confusing.. Can you please give an example? Thanks, -Jay
|
 |
Stefan Wagner
Ranch Hand
Joined: Jun 02, 2003
Posts: 1923
|
|
You didn't read my reply to your previous post - did you? Will you read this one, or start a new Thread?
|
http://home.arcor.de/hirnstrom/bewerbung
|
 |
 |
|
|
subject: Showing the first record by press a button
|
|
|