IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Setlocation Won't Work


kvarnerexpress
no avatar
Super Member
*********
Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



Post #1 post 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)




Go to the top of the page
+Quote Post
OpaQue
no avatar
Administrator
**************
Group: Admin
Posts: 1,583
Joined: 11-June 04
From: Somewhere in Time & Space.
Member No.: 1
myCENT:21.29



Post #2 post 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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   3 zachtk8702 511 2nd August 2005 - 04:30 PM
Last post by: cragllo
No New Posts   7 Saint_Michael 666 20th November 2004 - 08:02 PM
Last post by: swanx
No New Posts   7 Onizuka 570 19th August 2004 - 02:55 PM
Last post by: Shackman
No New Posts   4 DataHead 539 31st August 2004 - 09:44 PM
Last post by: spawn_syxx9
No New Posts   7 cangor 351 12th December 2008 - 05:50 PM
Last post by: networker
No New Posts   7 sanjay0828 687 5th February 2008 - 02:59 AM
Last post by: tricky77puzzle
No New Posts   3 serverph 472 4th January 2009 - 08:15 AM
Last post by: rpgsearcherz
No New Posts   1 Trystim 510 26th October 2004 - 01:15 PM
Last post by: hulunes
No New Posts   0 ljiljana 728 29th October 2004 - 08:13 AM
Last post by: ljiljana
No New Posts   8 pbrugge 398 30th October 2004 - 02:47 PM
Last post by: karlo
No New Posts   5 tyrant_dictator 969 15th January 2008 - 01:27 AM
Last post by: FeedBacker
No New Posts 1 karlo 368 13th November 2004 - 01:17 PM
Last post by: wassie
No New Posts   8 Good Grief Graphics 642 31st December 2004 - 05:58 AM
Last post by: omikronstudios
No New Posts   2 icedragn 680 28th December 2004 - 07:49 AM
Last post by: Zenchi
No New Posts   5 Neeraz 1,694 17th September 2007 - 03:19 PM
Last post by: bishoujo


 



RSS Open Discussion Time is now: 8th January 2009 - 09:49 AM