Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

GUI Help!

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
jtcy
Asked:
jtcy
  • 8
  • 6
  • 2
1 Solution
 
CEHJCommented:
Try using a JLabel + ImageIcon
0
 
expertmbCommented:
>>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
 
jtcyAuthor Commented:
Actually, my class extends JFrame, forgot to say that.

0
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.

 
jtcyAuthor Commented:
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
 
expertmbCommented:
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
 
jtcyAuthor Commented:
not sure though...

for the gridlayout, I still don get much from the site.
0
 
jtcyAuthor Commented:
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
 
CEHJCommented:
>>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
 
jtcyAuthor Commented:
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
 
CEHJCommented:
>>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
 
jtcyAuthor Commented:
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
 
CEHJCommented:
A kludgy way is to do

.... new JLabel("         ");
0
 
jtcyAuthor Commented:
??? What would that mean and do?
0
 
CEHJCommented:
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
 
jtcyAuthor Commented:
Hm~~ nevermind, I just found that I could use setborder() for the label~
0
 
CEHJCommented:
8-)
0

Featured Post

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.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now