Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.event.*;
- public class Window extends JFrame {
- JList list;
- JButton buttons;
- JComboBox<String> box;
- JTextField field;
- JPanel text;
- JRadioButton radioButton;
- private BildYta y;
- public Window() {
- super("Inlupp 2");
- setLayout(new BorderLayout());
- setSize(600, 400);
- // PLACERING
- JPanel upper = new JPanel();
- add(upper, BorderLayout.NORTH);
- JPanel leftCorner = new JPanel();
- leftCorner.setLayout(new BoxLayout(leftCorner, BoxLayout.Y_AXIS));
- upper.add(leftCorner);
- JPanel rightCorner = new JPanel();
- rightCorner.setLayout(new BoxLayout(rightCorner, BoxLayout.Y_AXIS));
- add(rightCorner, BorderLayout.EAST);
- JPanel lower = new JPanel();
- add(lower, BorderLayout.SOUTH);
- // MENY + DROP DOWN
- JMenuBar mbar = new JMenuBar();
- setJMenuBar(mbar);
- JMenu archiveMenu = new JMenu("Archive");
- mbar.add(archiveMenu);
- JMenuItem newMapItem = new JMenuItem("New Map");
- archiveMenu.add(newMapItem);
- newMapItem.addActionListener(new NewMapLyss());
- JMenuItem loadPlacesItem = new JMenuItem("Load Places");
- archiveMenu.add(loadPlacesItem);
- loadPlacesItem.addActionListener(new LoadPlacesLyss());
- JMenuItem saveItem = new JMenuItem("Save");
- archiveMenu.add(saveItem);
- saveItem.addActionListener(new SaveLyss());
- JMenuItem exitItem = new JMenuItem("Exit");
- archiveMenu.add(exitItem);
- exitItem.addActionListener(new ExitLyss());
- // RADIOKNAPPAR
- radioButton = new JRadioButton("Named", true);
- JRadioButton describedRadioButton = new JRadioButton("Described");
- ButtonGroup rbg = new ButtonGroup();
- rbg.add(radioButton);
- rbg.add(describedRadioButton);
- leftCorner.add(radioButton);
- leftCorner.add(describedRadioButton);
- // LABEL
- JLabel categoriesLabel = new JLabel("Categories");
- rightCorner.add(categoriesLabel);
- categoriesLabel.setText("Categories");
- // J-LIST
- String[] communication = { "Bus", "Underground", "Train" };
- JList<String> list = new JList<>(communication);
- rightCorner.add(list);
- list.setVisibleRowCount(3);
- list.setLayoutOrientation(JList.VERTICAL_WRAP);
- list.setFixedCellWidth(150);
- list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- //list.addListSelectionListener(new ListLyss());
- // KNAPPAR
- JTextField searchField = new JTextField("Search ");
- upper.add(searchField);
- JButton searchButton = new JButton("Search");
- upper.add(searchButton);
- searchButton.addActionListener(new searchButtonLyss());
- JButton hideButton = new JButton("Hide");
- upper.add(hideButton);
- hideButton.addActionListener(new hideButtonLyss());
- JButton removeButton = new JButton("Remove");
- upper.add(removeButton);
- removeButton.addActionListener(new removeButtonLyss());
- JButton coordinatesButton = new JButton("Coordinates");
- upper.add(coordinatesButton);
- coordinatesButton.addActionListener(new coordinatesButtonLyss());
- JButton hideCategoryButton = new JButton("Hide category");
- rightCorner.add(hideCategoryButton);
- hideCategoryButton.addActionListener(new hideCategoryButtonLyss());
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setVisible(true);
- // LYSSNARE TILL KNAPPARNA
- }
- public class searchButtonLyss implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent ave) {
- search();
- }
- public void search() {
- }
- }
- public class hideButtonLyss implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent ave) {
- hide();
- }
- public void hide() {
- }
- }
- public class removeButtonLyss implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent ave) {
- remove();
- }
- public void remove() {
- }
- }
- public class coordinatesButtonLyss implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent ave) {
- coordinates();
- }
- public void coordinates() {
- }
- }
- public class hideCategoryButtonLyss implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent ave) {
- hideCategory();
- }
- public void hideCategory() {
- }
- }
- // LYSSNARE TILL DROP DOWN
- class NewMapLyss implements ActionListener {
- public void actionPerformed(ActionEvent ave) {
- String str = System.getProperty("user/images/skola.dir");
- JFileChooser jfc = new JFileChooser(str);
- int svar = jfc.showOpenDialog(Window.this);
- if (svar == JFileChooser.APPROVE_OPTION) {
- File file = jfc.getSelectedFile();
- String path = file.getAbsolutePath();
- y = new BildYta(path);
- JScrollPane scroll = new JScrollPane(y);
- add(scroll, BorderLayout.CENTER);
- validate();
- repaint();
- }
- }
- }
- // LYSSNARE TILL JLIST
- // class ListLyss implements ListSelectionListener {
- // public void valueChanged(ListSelectionEvent lev) {
- // if (!lev.getValueIsAdjusting())
- // System.out.println(list.getSelectedValue());
- // }
- // }
- class BildYta extends JLabel {
- private ImageIcon image;
- BildYta(String path) {
- image = new ImageIcon(path);
- this.setIcon(image);
- setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
- }
- public ImageIcon getImage() {
- return image;
- }
- }
- class LoadPlacesLyss implements ActionListener {
- public void actionPerformed(ActionEvent ave) {
- }
- }
- class SaveLyss implements ActionListener {
- public void actionPerformed(ActionEvent ave) {
- }
- }
- class ExitLyss implements ActionListener {
- public void actionPerformed(ActionEvent ave) {
- }
- }
- public static void main(String[] args) {
- new Window();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement