Solved

GUI Help!

Posted on 2004-08-18
16
141 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 40 total points
Comment Utility
Try using a JLabel + ImageIcon
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
>>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
Comment Utility
Actually, my class extends JFrame, forgot to say that.

0
 

Author Comment

by:jtcy
Comment Utility
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
Comment Utility
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
Comment Utility
not sure though...

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

Author Comment

by:jtcy
Comment Utility
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
Comment Utility
>>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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jtcy
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
A kludgy way is to do

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

Author Comment

by:jtcy
Comment Utility
??? What would that mean and do?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
Hm~~ nevermind, I just found that I could use setborder() for the label~
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now