Advertisement
Guest User

Untitled

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