HW10 Solution2

HW10 Solution2 - public void actionPerformed(ActionEvent e...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import javax.swing.* import java.awt.* import java.awt.event.* public class ImageViewer extends JFrame { // Declare components as instance variables // so that the ActionListener can access them private JTextField text = new JTextField("Filename") private JButton button = new JButton("Open") private JLabel label = new JLabel("No Image") // Constructor public ImageViewer() { // Set up the frame setLayout(new FlowLayout()) add(text) add(button) add(label) // Add the event handlers button.addActionListener(new ActionListener() {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public void actionPerformed(ActionEvent e) { String filename = text.getText() java.io.File file = new java.io.File(filename) if (file.exists()) { label.setText("") label.setIcon(new ImageIcon(filename)) } else { label.setText("File not found.") label.setIcon(null) } } }) } // Main method public static void main(String args) { ImageViewer f = new ImageViewer() f.setTitle("Image Editor") f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) f.setSize(500, 600) f.setVisible(true) } }...
View Full Document

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

Ask a homework question - tutors are online