Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.AbstractAction;
- import javax.swing.JButton;
- import javax.swing.JPanel;
- import javax.swing.JFileChooser;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JOptionPane;
- import java.awt.BorderLayout;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.event.*;
- import java.awt.image.BufferedImage;
- import java.io.*;
- import javax.imageio.*;
- public class Game extends JFrame {
- //static JFrame frame;
- Game()
- {
- super("Robots see");
- setVisible(true);
- setSize(1400, 800);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JMenuBar menu = new JMenuBar();
- getContentPane().add(BorderLayout.NORTH, menu);
- JMenu btn_load = new JMenu("Открыть");
- JMenu btn_save = new JMenu("Сохранить");
- JMenu btn_saveAs = new JMenu("Сохранить как");
- JMenu btn_sets = new JMenu("Настройки");
- menu.add(btn_load);
- menu.add(btn_save);
- menu.add(btn_saveAs);
- menu.add(btn_sets);
- btn_load.addActionListener(new LoadClicked(this));
- }
- public static void main(String[] args) throws IOException {
- Game game = new Game();
- }
- }
- class LoadClicked implements ActionListener
- {
- static Game game;
- static BufferedImage image;
- LoadClicked(Game game)
- {
- this.game = game;
- }
- public void actionPerformed(ActionEvent e)
- {
- String filename;
- JFileChooser fileChooser = new JFileChooser();
- int result = fileChooser.showOpenDialog(null);
- // Если директория выбрана, покажем ее в сообщении
- try{ if (result == JFileChooser.APPROVE_OPTION )
- {
- filename = fileChooser.getSelectedFile().getAbsolutePath();
- image = ImageIO.read(new File(filename));
- }}
- catch(IOException e1) { }
- JPanel pane = new JPanel() {
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.drawImage(image, 0, 0, null);
- }
- };
- game.add(pane);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement