Skip to content

Instantly share code, notes, and snippets.

@crzye8s
Forked from BobTheBuilderBot/gist:3856934
Created October 17, 2012 09:34
Show Gist options
  • Select an option

  • Save crzye8s/3904683 to your computer and use it in GitHub Desktop.

Select an option

Save crzye8s/3904683 to your computer and use it in GitHub Desktop.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ImageZoom implements ActionListener {
private JFrame windowFrame;
private ImagePanel imagePanel;
final JFileChooser fileChooser = new JFileChooser();
public static void main(String[] args) {
ImageZoom imageZoomApp = new ImageZoom();
imageZoomApp.createWindow();
imageZoomApp.createElements();
}
public void createWindow() {
windowFrame = new JFrame("Testing");
windowFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
windowFrame.setPreferredSize(new Dimension(640, 480));
windowFrame.setVisible(true);
}
public void createElements() {
JMenu menu, submenu;
JMenuItem menuItem;
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("Test Menu");
menuBar.add(menu);
menuItem = new JMenuItem("A text-only menu item");
menu.add(menuItem);
menuItem.setActionCommand("openImage");
menuItem.addActionListener(this);
imagePanel = new ImagePanel();
windowFrame.add(imagePanel);
windowFrame.setJMenuBar(menuBar);
windowFrame.pack();
}
@Override
public void actionPerformed(ActionEvent event) {
if(event.getActionCommand() == "openImage") {
fileChooser.showOpenDialog(windowFrame);
int returnVal = fileChooser.showOpenDialog(windowFrame);
if(returnVal == JFileChooser.APPROVE_OPTION) {
imagePanel.loadImage(fileChooser.getSelectedFile().getPath());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment