ConnectHandheld.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package connection;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.io.IOException;
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9. import javax.swing.JScrollPane;
  10. import javax.swing.JSplitPane;
  11. import javax.swing.JTextArea;
  12. import javax.swing.JTextField;
  13. import api.Algorithm;
  14. import connection.socket.Server;
  15. import ui.controller.Control;
  16. import ui.view.Console;
  17. public class ConnectHandheld implements Algorithm{
  18. //Holeg
  19. Control control;
  20. //Gui
  21. private JPanel content = new JPanel();
  22. private JTextArea textArea;
  23. //RMI
  24. int port = 4242;
  25. private Console console;
  26. public static void main(String[] args)
  27. {
  28. JFrame newFrame = new JFrame("exampleWindow");
  29. ConnectHandheld instance = new ConnectHandheld();
  30. newFrame.setContentPane(instance.getAlgorithmPanel());
  31. newFrame.pack();
  32. newFrame.setVisible(true);
  33. newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34. }
  35. public ConnectHandheld() {
  36. content.setLayout(new BorderLayout());
  37. textArea = new JTextArea();
  38. textArea.setEditable(false);
  39. console = new Console();
  40. JScrollPane scrollPane = new JScrollPane(console);
  41. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
  42. createSettingsPanel() , scrollPane);
  43. splitPane.setResizeWeight(0.0);
  44. content.add(splitPane, BorderLayout.CENTER);
  45. content.setPreferredSize(new Dimension(400,600));
  46. }
  47. private JPanel createSettingsPanel() {
  48. JPanel settingsPanel = new JPanel(null);
  49. settingsPanel.setPreferredSize(new Dimension(400, 400));
  50. settingsPanel.setMinimumSize(new Dimension(400, 225));
  51. JLabel portLabel = new JLabel("Port:");
  52. portLabel.setBounds(10, 20, 35, 30);
  53. settingsPanel.add(portLabel);
  54. JTextField portTF = new JTextField(""+port);
  55. portTF.setBounds(55 ,20, 80, 30);
  56. settingsPanel.add(portTF);
  57. JButton connectButton = new JButton("Start Server");
  58. connectButton.setBounds(100 ,175, 200, 50);
  59. connectButton.addActionListener(actionEvent -> connect());
  60. settingsPanel.add(connectButton);
  61. return settingsPanel;
  62. }
  63. private void connect() {
  64. console.println("Start Server on Port:" + port);
  65. try {
  66. Server server = new Server(port, console);
  67. } catch (IOException e) {
  68. // TODO Auto-generated catch block
  69. e.printStackTrace();
  70. }
  71. }
  72. @Override
  73. public JPanel getAlgorithmPanel() {
  74. return content;
  75. }
  76. @Override
  77. public void setController(Control control) {
  78. this.control = control;
  79. }
  80. }