Results 1 to 8 of 8
Thread: GUI's
- 07-26-2009, 02:19 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
- 07-26-2009, 02:50 AM #2
It depends. If its purely textual information you want to convey, it can be pretty simple. NetBeans has a built in GUI builder that is all drag 'n' drop. I suggest trying it out.
- 07-26-2009, 03:01 AM #3
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
I dont have NetBeans. I have a customized JCreator. It came on a CD with Java For Dummies (edition 4). And I wanted GUI for the user input. With text boxes and all.
- 07-26-2009, 03:10 AM #4
Its free, I suggest you download it and give it a try:
Welcome to NetBeans
- 07-26-2009, 03:12 AM #5
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
No, I'd prefer JCreator. So I can follow the instructions in Java for Dummies. I might get it when I finish the book. Maybe. Only if I think it's better. But can you (or anyone) answer my original question.
- 07-26-2009, 03:27 AM #6
Well, I'll paste in the code for a simple GUI with text input and output in a minute, but I think if you are planning on coding it from scratch it'll be a bit of a learning curve for you.
Java Code:package test; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; /** * @author Steffen Gates */ public class GUI { public static void main(String[] args) { new GUI(); } JFrame window; //The whole window JPanel panel; //A place to put things in the window JTextField textIn; //input JLabel label; //output JButton button; //simple button public GUI(){ window = new JFrame(); window.setSize(640, 150); window.setLocationRelativeTo(null); //Center the window panel = new JPanel(); textIn = new JTextField(); textIn.setColumns(50); //50 char's wide label = new JLabel("Lets Print Something!"); //default output button = new JButton("Click Me!"); button.addActionListener(new ButtonListener()); //make button do something panel.add(textIn); //Add everything to the panel panel.add(label); panel.add(button); window.add(panel); //add panel to the window window.setVisible(true); //make window visible } //To make an action listener, just make a class that implements //ActionListener and has a method called actionPerformed() class ButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e) { if(e.getActionCommand().compareTo("Click Me!") == 0) label.setText(textIn.getText()); } } }Last edited by quad64bit; 07-26-2009 at 03:35 AM.
- 07-26-2009, 03:32 AM #7
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
Wouldn't it have been easier to use
import java.awt.event.*;
import javax.swing.*;
- 07-26-2009, 03:38 AM #8
Importing unneeded packages is wasteful. When projects get large, importing everything increases compile time a great deal. If your program had 100 classes and 100,000 lines+ of code, it could take many many extra minutes, or even hours.
As such, when you use a good IDE, it will import only what is needed and as needed. In netbeans, when I type my code, the imports happen automatically; therefor there are many import statements, but they are specific.
Its no extra work on my part, as I said its automatic.
PS: I added some comments to the code. Also, since you are doing this by hand, you're required to readup quite a bit about some of the simpler parts of GUI design. Read up about layout managers, as its the only way to get your gui laid out the way you want. I suggest a grid layout or border layout.Last edited by quad64bit; 07-26-2009 at 03:43 AM.
Similar Threads
-
Swing themes & custom GUI's
By Mr.Beans in forum AWT / SwingReplies: 3Last Post: 04-28-2009, 02:10 AM -
GUI's
By diggitydoggz in forum New To JavaReplies: 2Last Post: 12-22-2008, 09:19 PM -
Creating GUI's for simulators.
By Modifier in forum New To JavaReplies: 3Last Post: 11-20-2008, 12:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks