?
Solved

GUI Help!

Posted on 2004-08-18
16
Medium Priority
?
160 Views
Last Modified: 2012-05-05
Okay, now....I have a map, which is a text file. And...My program would need to load this file and then show this map in my user graphical interface. Which component should i use to show the map? ALso, the user must be able to do interactive actions on the map.

0
Comment
Question by:jtcy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
16 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 11829504
Try using a JLabel + ImageIcon
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11829510
>>I have a map, which is a text file
wht this file contains ?

>> Which component should i use to show the map?
you can use jpanel.
0
 

Author Comment

by:jtcy
ID: 11829511
Actually, my class extends JFrame, forgot to say that.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jtcy
ID: 11829527
Also, here is my class:

public class GUI extends JFrame
 {
       
       
       // Items under File                                                            
    JMenuItem Load = new JMenuItem("Load");            
    JMenuItem Quit = new JMenuItem("Quit");
   
    // Items under View                
    JMenuItem Status = new JMenuItem("Show Status");          
   
    // Items under Help
    JMenuItem Version = new JMenuItem("About HeavyComponent");                      
    JMenuItem Documents = new JMenuItem("User Manual");
       
       // Text area to show status
       TextArea status = new TextArea(5,50);
       
       
       GridBagConstraints constraints_start;
    GridBagConstraints constraints_end;
       
       
       
    public GUI()
      {
          super("Heavy Component ver.1.0");

            getContentPane().setLayout(new GridBagLayout());          // Set layout information for application.
            constraints_start = new GridBagConstraints();
            constraints_start.weightx = 1.0;
            constraints_end = new GridBagConstraints();
            constraints_end.weightx = 1.0;
            constraints_end.gridwidth = GridBagConstraints.REMAINDER;

          JPopupMenu.setDefaultLightWeightPopupEnabled(false);

            JMenuBar bar = new JMenuBar();                            // Create a menu bar.
            setJMenuBar(bar);

            JMenu FileMenu = new JMenu("File");                      
            FileMenu.add(Load);                                
            Load.setEnabled(true);                              
            FileMenu.add(Quit);
            Quit.setEnabled(true);
            
            JMenu ViewMenu = new JMenu("View");
            ViewMenu.add(Status);
            
            JMenu HelpMenu = new JMenu("Help");
            HelpMenu.add(Version);
            HelpMenu.add(Documents);
            
            bar.add(FileMenu);
            bar.add(ViewMenu);
            bar.add(HelpMenu);
            
            getContentPane().add(status, constraints_end);

            pack();
            show();
            Dimension d = getSize();
            setSize((int)d.getWidth()+200,(int)d.getHeight()+350);
            show();
            
            
        
        }


Can someone tell me how to set the textArea to...the right bottom? I want it to appear at right bottom so that some control buttons are at left bottom, and then the map will appear on top of them. Which part of my code sets the layout? I only know how to write but don't know what they mean~~ (sometimes)~


0
 
LVL 6

Expert Comment

by:expertmb
ID: 11829620
for gridbaglayout.

http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

from the file content are you constructing the map. does this file contains some rgb values etc..,?
0
 

Author Comment

by:jtcy
ID: 11829678
not sure though...

for the gridlayout, I still don get much from the site.
0
 

Author Comment

by:jtcy
ID: 11851457
Okay, so which components should I use to display the map? The map is likely to be an XML file. I need to display the map (contains nodes with links linking each nodes) on the interface. The problem is, the user needs to be able to click on any links on the map and some actions will get initiated. Which component allows displaying smth and also allows interactive actions on it (e.g. clicking on it)?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11851533
>>Which component allows displaying smth and also allows interactive actions on it (e.g. clicking on it)?

Any component will allow that. A JLabel will be the easiest maybe. Add a MouseListener to it
0
 

Author Comment

by:jtcy
ID: 11858126
Okay, how can I load a file into my program and make it appear in the label? The loading part would be okay. What bugs me is how can I make the label present the input? Suppose the input map is a txt file, how can I implement that?


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11858188
>>I need to display the map (contains nodes with links linking each nodes) on the interface.

Sounds to me more like you'd need a JTree possibly. Difficult to say exactly without knowing more.
0
 

Author Comment

by:jtcy
ID: 11858308
Okay, I have used a tool to set up the interface and everything has been done nicely. I have used JLabel for presenting the map. Um....the problem is, how can I make the label having border? I mean, apparently it is just like invisible when there is no text on the label. How can I set border around JLabel?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11858323
A kludgy way is to do

.... new JLabel("         ");
0
 

Author Comment

by:jtcy
ID: 11858547
??? What would that mean and do?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11858574
It would mean that the label would not be 'invisible' if it had no caption.

>>when there is no text on the label

How are you setting the text on the label?
0
 

Author Comment

by:jtcy
ID: 11858608
Hm~~ nevermind, I just found that I could use setborder() for the label~
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11944616
8-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question