Tutorial09 - Tutorial #9: GUIs OPTIONAL Introduction: This...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial #9: GUIs O P T I O N A L Introduction: This tutorial is recommended if you have limited experience creating a GUI with components and event handlers. 1. Create a file called MyGUI.java with the following code. Be sure to type “extends JFrame” after the class name. You may omit the comments if you wish. Note that this is a template class with a constructor as well as a main method, unlike what we have done in the past. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyGUI extends JFrame { // Declare components as instance variables // so that the ActionListener can access them private JTextField myText = new JTextField(""); private JButton myButton = new JButton("Go"); // Constructor public MyGUI() { // Set up the frame setLayout(new GridLayout(2, 1, 5, 5)); add(myText); add(myButton); } // Main method public static void main(String[] args) { MyGUI myFrame = new MyGUI(); myFrame.setTitle("This is my first GUI!"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This test prep was uploaded on 04/10/2008 for the course ENGR 131 taught by Professor Xiaowei during the Spring '07 term at Case Western.

Page1 / 2

Tutorial09 - Tutorial #9: GUIs OPTIONAL Introduction: This...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online