GUI is just a shell wrapping around your real work. In other words, it is more like a presentation. If you have done any program that displays results on monitor, you can add GUI to it, such as replace how you enter inputs or display the output.
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 376
Skill Endorsements: 17
Try BorderLayout. I'll try to give you a step-by-step walkthrough:
- Create a JFrame -
public class MyFrame extends JFrame { ... } - Get the content pane -
JPanel contentPane = (JPanel) this.getContentPane() - Set layout manager to BorderLayout -
contentPane.setLayout(new BorderLayout()) - Add a text area in the centre of the frame -
contentPane.add(new JTextArea("my text"), BorderLayout.CENTER) - Add a button to the top of the frame -
contentPane.add(new JButton("my button"), BorderLayout.NORTH) - Make the frame visible so you can actually see all of this -
this.setVisible(true)
Some slightly more difficult things to try:
- Create the JButton and JTextArea outside of the method call so that you can reference them with a variable later -
private JButton myButton = new JButton("my button"); - Create a listener for the button, that changes the text in the JTextArea when it is clicked -
myButton.addActionListener(this) , and put code into an actionPerformed(...) method
leiger
Junior Poster in Training
91 posts since Jun 2010
Reputation Points: 33
Solved Threads: 7
Skill Endorsements: 0