Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GUI Help!

Posted on 2004-08-18
16
Medium Priority
?
164 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
  • 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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

972 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