Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionListener;
  7. import java.io.File;
  8. import java.util.Vector;
  9.  
  10. import javax.swing.BorderFactory;
  11. import javax.swing.JButton;
  12. import javax.swing.JFileChooser;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JPanel;
  16. import javax.swing.JScrollPane;
  17. import javax.swing.JSplitPane;
  18. import javax.swing.JTable;
  19. import javax.swing.JTextField;
  20. import javax.swing.border.EmptyBorder;
  21.  
  22.  
  23. public class Window extends JFrame implements ActionListener {
  24.  
  25. static private final String newline = "\n";
  26. protected JTextField textField;
  27. JPanel p1,p2,p3;
  28. Dimension dimension1,dimension2,dimension3;
  29. JButton OpenButton;
  30. JButton SaveButton;
  31. JFileChooser fc;
  32.  
  33. public Window() {
  34.  
  35. setLayout(new FlowLayout());
  36.  
  37. //-------------PANELS-----------
  38.  
  39. p1=new JPanel(new GridLayout(2,2));
  40. p2=new JPanel();
  41. p3=new JPanel();
  42.  
  43. dimension1=new Dimension(500,50);
  44. dimension2=new Dimension(500,160);
  45. dimension3=new Dimension(500,50);
  46.  
  47. p1.setPreferredSize(dimension1);
  48. p2.setPreferredSize(dimension2);
  49. p3.setPreferredSize(dimension3);
  50.  
  51. p1.setBackground(Color.GRAY);
  52. p2.setBackground(Color.DARK_GRAY);
  53. p3.setBackground(Color.BLUE);
  54.  
  55.  
  56.  
  57. add(p1);
  58. add(p2);
  59. add(p3);
  60.  
  61. //----------------TEXT FIELDS-------------
  62.  
  63. JLabel label1=new JLabel("Host");
  64. label1.setHorizontalTextPosition(11);
  65. JLabel label2=new JLabel("Port");
  66. JTextField textField = new JTextField(10);
  67. JTextField textField1 = new JTextField(10);
  68. p1.add(label1);
  69. p1.add(label2);
  70. p1.add(textField);
  71. p1.add(textField1);
  72.  
  73.  
  74. p1.setBorder(new EmptyBorder(10,30,10,30));
  75. textField.addActionListener(this);
  76. textField1.addActionListener(this);
  77.  
  78.  
  79.  
  80.  
  81. //-------------------TABLES-------------
  82.  
  83. Vector<String> columnNames =new Vector<>();
  84. columnNames.add("Name" );
  85. columnNames.add("Size" );
  86.  
  87. Vector<Vector> data= new Vector<>();
  88. Vector<String> s =new Vector<>();
  89.  
  90.  
  91. s.add("plik_1");
  92. s.add("100");
  93.  
  94. data.add(s);
  95.  
  96.  
  97. Table table = new Table(data, columnNames);
  98. JScrollPane pane=new JScrollPane(table);
  99. pane.setBorder(BorderFactory.createLineBorder(Color.black));
  100. p2.add(pane);
  101.  
  102.  
  103. //-----------------BUTTONS------------
  104.  
  105. OpenButton = new JButton("Open");
  106. p2.add(OpenButton);
  107. OpenButton.addActionListener(this);
  108.  
  109.  
  110. SaveButton = new JButton("Save");
  111. p2.add(SaveButton);
  112. SaveButton.addActionListener(this);
  113.  
  114.  
  115.  
  116.  
  117. //-------------------FILE CHOOSER-------------
  118. JFileChooser fc= new JFileChooser();
  119.  
  120. JFrame frame = new JFrame("FileChooserDemo");
  121.  
  122. frame.add(new FileChooserDemo());
  123.  
  124.  
  125.  
  126. setTitle("Path");
  127. setSize(550,300);
  128.  
  129.  
  130. }
  131.  
  132.  
  133.  
  134.  
  135. public void actionPerformed(ActionEvent e) {
  136.  
  137. /*if (e.getActionCommand().equals("Open"))
  138. System.out.println("Open");
  139. else
  140. System.out.println("not Open");
  141.  
  142. if (e.getActionCommand().equals("Save"))
  143. System.out.println("Save");
  144. else
  145. System.out.println("not Save");*/
  146.  
  147. //Handle open button action.
  148. if (e.getSource() == OpenButton) {
  149. int returnVal = fc.showOpenDialog(JFileChooserDemo.this);
  150.  
  151. if (returnVal == JFileChooser.APPROVE_OPTION) {
  152. File file = fc.getSelectedFile();
  153. //This is where a real application would open the file.
  154. log.append("Opening: " + file.getName() + "." + newline);
  155. } else {
  156. log.append("Open command cancelled by user." + newline);
  157. }
  158. log.setCaretPosition(log.getDocument().getLength());
  159.  
  160. //Handle save button action.
  161. } else if (e.getSource() == saveButton) {
  162. int returnVal = fc.showSaveDialog(FileChooserDemo.this);
  163. if (returnVal == JFileChooser.APPROVE_OPTION) {
  164. File file = fc.getSelectedFile();
  165. //This is where a real application would save the file.
  166. log.append("Saving: " + file.getName() + "." + newline);
  167. } else {
  168. log.append("Save command cancelled by user." + newline);
  169. }
  170. log.setCaretPosition(log.getDocument().getLength());
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177. }
  178.  
  179.  
  180.  
  181. //okno srwera może wygladać tak samo, szukać RMI
  182.  
  183.  
  184.  
  185. public static void main(String[] args) {
  186. Window okno=new Window();
  187. okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  188. okno.setVisible(true);
  189. }
  190.  
  191.  
  192.  
  193.  
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement