Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionListener;
- import java.io.File;
- import java.util.Vector;
- import javax.swing.BorderFactory;
- import javax.swing.JButton;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JSplitPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.border.EmptyBorder;
- public class Window extends JFrame implements ActionListener {
- static private final String newline = "\n";
- protected JTextField textField;
- JPanel p1,p2,p3;
- Dimension dimension1,dimension2,dimension3;
- JButton OpenButton;
- JButton SaveButton;
- JFileChooser fc;
- public Window() {
- setLayout(new FlowLayout());
- //-------------PANELS-----------
- p1=new JPanel(new GridLayout(2,2));
- p2=new JPanel();
- p3=new JPanel();
- dimension1=new Dimension(500,50);
- dimension2=new Dimension(500,160);
- dimension3=new Dimension(500,50);
- p1.setPreferredSize(dimension1);
- p2.setPreferredSize(dimension2);
- p3.setPreferredSize(dimension3);
- p1.setBackground(Color.GRAY);
- p2.setBackground(Color.DARK_GRAY);
- p3.setBackground(Color.BLUE);
- add(p1);
- add(p2);
- add(p3);
- //----------------TEXT FIELDS-------------
- JLabel label1=new JLabel("Host");
- label1.setHorizontalTextPosition(11);
- JLabel label2=new JLabel("Port");
- JTextField textField = new JTextField(10);
- JTextField textField1 = new JTextField(10);
- p1.add(label1);
- p1.add(label2);
- p1.add(textField);
- p1.add(textField1);
- p1.setBorder(new EmptyBorder(10,30,10,30));
- textField.addActionListener(this);
- textField1.addActionListener(this);
- //-------------------TABLES-------------
- Vector<String> columnNames =new Vector<>();
- columnNames.add("Name" );
- columnNames.add("Size" );
- Vector<Vector> data= new Vector<>();
- Vector<String> s =new Vector<>();
- s.add("plik_1");
- s.add("100");
- data.add(s);
- Table table = new Table(data, columnNames);
- JScrollPane pane=new JScrollPane(table);
- pane.setBorder(BorderFactory.createLineBorder(Color.black));
- p2.add(pane);
- //-----------------BUTTONS------------
- OpenButton = new JButton("Open");
- p2.add(OpenButton);
- OpenButton.addActionListener(this);
- SaveButton = new JButton("Save");
- p2.add(SaveButton);
- SaveButton.addActionListener(this);
- //-------------------FILE CHOOSER-------------
- JFileChooser fc= new JFileChooser();
- JFrame frame = new JFrame("FileChooserDemo");
- frame.add(new FileChooserDemo());
- setTitle("Path");
- setSize(550,300);
- }
- public void actionPerformed(ActionEvent e) {
- /*if (e.getActionCommand().equals("Open"))
- System.out.println("Open");
- else
- System.out.println("not Open");
- if (e.getActionCommand().equals("Save"))
- System.out.println("Save");
- else
- System.out.println("not Save");*/
- //Handle open button action.
- if (e.getSource() == OpenButton) {
- int returnVal = fc.showOpenDialog(JFileChooserDemo.this);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- //This is where a real application would open the file.
- log.append("Opening: " + file.getName() + "." + newline);
- } else {
- log.append("Open command cancelled by user." + newline);
- }
- log.setCaretPosition(log.getDocument().getLength());
- //Handle save button action.
- } else if (e.getSource() == saveButton) {
- int returnVal = fc.showSaveDialog(FileChooserDemo.this);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- //This is where a real application would save the file.
- log.append("Saving: " + file.getName() + "." + newline);
- } else {
- log.append("Save command cancelled by user." + newline);
- }
- log.setCaretPosition(log.getDocument().getLength());
- }
- }
- //okno srwera może wygladać tak samo, szukać RMI
- public static void main(String[] args) {
- Window okno=new Window();
- okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- okno.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement