practice_GUIs

practice_GUIs - Answer import javax.swing.*; import...

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

View Full Document Right Arrow Icon
Practice– CSE 205 – Fall 2008 Last Name ______________________ First__________________ Last Name ______________________ First__________________ Date : 9/29/08 1. Complete this unfinished class such that each time the user enters the year they began college, the graduation year is shown in the lower right corner of the window (leave the user's input in the text field). Here is a before and after view of the graphical user interface when the user enters 2001 for the first time. Hint: Think about what is missing. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUIExample { public static void main(String[] args) { //create a frame object //Create a GraduationPanel and add it to the frame content pane } } class GraduationPanel extends JPanel { private JTextField year; //gets the year private JLabel graduationYear; // shows the graduation year public GraduationPanel() { } private class GraduateListener implements ActionListener { public void actionPerformed (ActionEvent e) { } }
Background image of page 1

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

View Full DocumentRight Arrow Icon
}//end of class
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Answer import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Quiz3 { public static void main(String args) { JFrame frame = new JFrame("When do I graduate?"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraduationPanel panel = new GraduationPanel(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } } class GraduationPanel extends JPanel { private JTextField year; private JLabel graduationYear; public GraduationPanel() { add(new JLabel("Enter college in")); year = new JTextField(5); add(year); year.addActionListener(new GraduateListener()); add(new JLabel("Graduation Year")); graduationYear = new JLabel("????"); add(graduationYear); setPreferredSize(new Dimension(210, 80)); } private class GraduateListener implements ActionListener { public void actionPerformed (ActionEvent e) { String text = year.getText(); int year = Integer.parseInt(text) + 4; graduationYear.setText("" +year); } } }...
View Full Document

This note was uploaded on 06/11/2009 for the course CS 205214 taught by Professor Balasooriya/kouvetakis during the Spring '09 term at ASU.

Page1 / 3

practice_GUIs - Answer import javax.swing.*; import...

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

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