-
-
Save crzye8s/3904683 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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