123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package connection;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.io.IOException;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JSplitPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import api.Algorithm;
- import connection.socket.Server;
- import ui.controller.Control;
- import ui.view.Console;
- public class ConnectHandheld implements Algorithm{
-
- //Holeg
- Control control;
-
- //Gui
- private JPanel content = new JPanel();
- private JTextArea textArea;
-
- //RMI
- int port = 4242;
- private Console console;
-
- public static void main(String[] args)
- {
- JFrame newFrame = new JFrame("exampleWindow");
- ConnectHandheld instance = new ConnectHandheld();
- newFrame.setContentPane(instance.getAlgorithmPanel());
- newFrame.pack();
- newFrame.setVisible(true);
- newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
-
-
-
-
- public ConnectHandheld() {
- content.setLayout(new BorderLayout());
-
- textArea = new JTextArea();
- textArea.setEditable(false);
- console = new Console();
- JScrollPane scrollPane = new JScrollPane(console);
- JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
- createSettingsPanel() , scrollPane);
- splitPane.setResizeWeight(0.0);
- content.add(splitPane, BorderLayout.CENTER);
- content.setPreferredSize(new Dimension(400,600));
- }
-
- private JPanel createSettingsPanel() {
- JPanel settingsPanel = new JPanel(null);
- settingsPanel.setPreferredSize(new Dimension(400, 400));
- settingsPanel.setMinimumSize(new Dimension(400, 225));
- JLabel portLabel = new JLabel("Port:");
- portLabel.setBounds(10, 20, 35, 30);
- settingsPanel.add(portLabel);
- JTextField portTF = new JTextField(""+port);
- portTF.setBounds(55 ,20, 80, 30);
- settingsPanel.add(portTF);
- JButton connectButton = new JButton("Start Server");
- connectButton.setBounds(100 ,175, 200, 50);
- connectButton.addActionListener(actionEvent -> connect());
- settingsPanel.add(connectButton);
- return settingsPanel;
- }
- private void connect() {
- console.println("Start Server on Port:" + port);
- try {
- Server server = new Server(port, console);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public JPanel getAlgorithmPanel() {
- return content;
- }
- @Override
- public void setController(Control control) {
- this.control = control;
- }
-
- }
|