|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
Post
#1
Jan 18 2006, 10:40 PM
I'm having trouble getting my applet's layout set up properly. I can't get any layout other then GridLayout to work, and GridLayout doesn't look all that great because I would like to make the graph bigger then the buttons, etc. I've tried using other layout managers, but I couldn't get any of them to work... so then I continued researching, and I found mention of a way to arrange things using setLocation? I tried it... but it just won't work! I use it... and theres no differance in location, although the code doesnt error. So now I'm stuck. Please, any help would be appreciated... the project is due on Friday, and I've gotten stuck on such a small part... thanks again! Code we've got so far: Code: CODE import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.util.*; import java.io.*; public class CPT extends JPanel implements ActionListener { JButton ModifyEntriesButton, ViewEntriesButton, SearchEntriesButton, SaveButton, BackButton; private final static String newline = "\n"; private DefaultTableModel model; public CPT () { super (new GridLayout (3, 0)); model = new PropertiesModel ("entries.data"); ModifyEntriesButton = new JButton ("Modify Entries"); ModifyEntriesButton.setVerticalTextPosition (AbstractButton.TOP); ModifyEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT); ModifyEntriesButton.setToolTipText ("Click this button to modify database entries."); ModifyEntriesButton.setMnemonic (KeyEvent.VK_M); ModifyEntriesButton.setActionCommand ("ModifyEntries"); ModifyEntriesButton.addActionListener (this); ViewEntriesButton = new JButton ("View Entries"); ViewEntriesButton.setVerticalTextPosition (AbstractButton.CENTER); ViewEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT); ViewEntriesButton.setToolTipText ("Click this button to add view all database entries."); ViewEntriesButton.setMnemonic (KeyEvent.VK_V); ViewEntriesButton.setActionCommand ("ViewEntries"); ViewEntriesButton.addActionListener (this); SearchEntriesButton = new JButton ("Search Entries"); SearchEntriesButton.setVerticalTextPosition (AbstractButton.BOTTOM); SearchEntriesButton.setHorizontalTextPosition (AbstractButton.LEFT); SearchEntriesButton.setToolTipText ("Click this button to search through all database entries."); SearchEntriesButton.setMnemonic (KeyEvent.VK_S); SearchEntriesButton.setActionCommand ("SearchEntries"); SearchEntriesButton.addActionListener (this); SaveButton = new JButton ("Save"); SaveButton.setVerticalTextPosition (AbstractButton.TOP); SaveButton.setHorizontalTextPosition (AbstractButton.RIGHT); SaveButton.setToolTipText ("Click this button to save database entries."); SaveButton.setMnemonic (KeyEvent.VK_S); SaveButton.setActionCommand ("Save"); SaveButton.addActionListener (this); BackButton = new JButton ("Back"); BackButton.setVerticalTextPosition (AbstractButton.BOTTOM); BackButton.setHorizontalTextPosition (AbstractButton.RIGHT); BackButton.setToolTipText ("Click this button to return to the main menu."); BackButton.setMnemonic (KeyEvent.VK_B); BackButton.setActionCommand ("Back"); BackButton.addActionListener (this); add (ModifyEntriesButton); add (ViewEntriesButton); add (SearchEntriesButton); } class PropertiesModel extends DefaultTableModel { public PropertiesModel (String filename) { addColumn ("Item Number"); addColumn ("Description"); addColumn ("Price"); //Fill model with data from property file Properties props = readFile (filename); if (props != null) { Enumeration coll = props.keys (); while (coll.hasMoreElements ()) { String property = (String) coll.nextElement (); String value = props.getProperty (property, ""); addRow (new Object[] { property, value } ); } } } } private Properties readFile (String filename) { try { Properties props = new Properties (); props.load (new FileInputStream (filename)); return props; } catch (IOException ioe) { return null; } } private boolean saveFile (String filename) { try { Properties props = new Properties (); for (int i = 0; i < model.getRowCount (); i++) props.put (model.getValueAt (i, 0), model.getValueAt (i, 1)); props.store (new FileOutputStream (filename), null); return true; } catch (IOException ioe) { return false; } } private void ModifyEntriesFunction () { removeAll (); add (new JScrollPane (new JTable (model))); //add (new JScrollPane (new JTable (model)), BorderLayout.CENTER); add (SaveButton); add (BackButton); invalidate (); updateUI (); } public void actionPerformed (ActionEvent e) { if ("ModifyEntries".equals (e.getActionCommand ())) { ModifyEntriesFunction (); } if ("ViewEntries".equals (e.getActionCommand ())) { removeAll (); add (BackButton); invalidate (); updateUI (); } if ("SearchEntries".equals (e.getActionCommand ())) { removeAll (); add (BackButton); invalidate (); updateUI (); } if ("Back".equals (e.getActionCommand ())) { removeAll (); add (ModifyEntriesButton); add (ViewEntriesButton); add (SearchEntriesButton); invalidate (); updateUI (); } if ("Save".equals (e.getActionCommand ())) { if (saveFile ("entries.data")) JOptionPane.showMessageDialog (null, "File saved successfully."); else JOptionPane.showMessageDialog (null, "File could not be saved!"); } } // Create the GUI and show it. For thread safety, // this method should be invoked from the // event-dispatching thread. private static void createAndShowGUI () { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated (true); //Create and set up the window. JFrame frame = new JFrame ("Swisha Computer House"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new CPT (); newContentPane.setOpaque (true); //content panes must be opaque frame.setContentPane (newContentPane); //Display the window. frame.pack (); frame.setSize (300, 300); frame.setVisible (true); } public static void main (String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater (new Runnable () { public void run () { createAndShowGUI (); } } ); } }Attached Images proj.JPG (31.9 KB, 2 views) |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin
Posts: 1,583 Joined: 11-June 04 From: Somewhere in Time & Space. Member No.: 1 myCENT:21.29 |
Post
#2
Jan 19 2006, 12:05 PM
I wish if this was something related to PHP :-S I'd really appreciate if anyone could come forward and provide a solution. kvarnerexpress, if you happen to find out the solution, please update this thread. |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
3 | zachtk8702 | 511 | 2nd August 2005 - 04:30 PM Last post by: cragllo |
|||
![]() |
7 | Saint_Michael | 666 | 20th November 2004 - 08:02 PM Last post by: swanx |
|||
![]() |
7 | Onizuka | 570 | 19th August 2004 - 02:55 PM Last post by: Shackman |
|||
![]() |
4 | DataHead | 539 | 31st August 2004 - 09:44 PM Last post by: spawn_syxx9 |
|||
![]() |
7 | cangor | 351 | 12th December 2008 - 05:50 PM Last post by: networker |
|||
![]() |
7 | sanjay0828 | 687 | 5th February 2008 - 02:59 AM Last post by: tricky77puzzle |
|||
![]() |
3 | serverph | 472 | 4th January 2009 - 08:15 AM Last post by: rpgsearcherz |
|||
![]() |
1 | Trystim | 510 | 26th October 2004 - 01:15 PM Last post by: hulunes |
|||
![]() |
0 | ljiljana | 728 | 29th October 2004 - 08:13 AM Last post by: ljiljana |
|||
![]() |
8 | pbrugge | 398 | 30th October 2004 - 02:47 PM Last post by: karlo |
|||
![]() |
5 | tyrant_dictator | 969 | 15th January 2008 - 01:27 AM Last post by: FeedBacker |
|||
![]() |
1 | karlo | 368 | 13th November 2004 - 01:17 PM Last post by: wassie |
|||
![]() |
8 | Good Grief Graphics | 642 | 31st December 2004 - 05:58 AM Last post by: omikronstudios |
|||
![]() |
2 | icedragn | 680 | 28th December 2004 - 07:49 AM Last post by: Zenchi |
|||
![]() |
5 | Neeraz | 1,694 | 17th September 2007 - 03:19 PM Last post by: bishoujo |
|||
|
Open Discussion | Time is now: 8th January 2009 - 09:49 AM |