void setupGUI() {
    taDictionary = new TextArea();
    taDictionary.setLocation(0, 0);
    taDictionary.setSize(106, 567);
    taDictionary.setBackground(new Color(-1));
    taDictionary.setText("");
    taDictionary.setRows(5);
    taDictionary.setColumns(1);
    getContentPane().add(taDictionary);

    tfSourc = new TextField();
    tfSourc.setLocation(224, 90);
    tfSourc.setSize(266, 25);
    tfSourc.setBackground(new Color(-1));
    tfSourc.setText("");
    tfSourc.setColumns(10);
    getContentPane().add(tfSourc);

    lblSourc = new Label();
    lblSourc.setLocation(106, 90);
    lblSourc.setSize(119, 25);
    lblSourc.setText("Source Word:");
    getContentPane().add(lblSourc);
    /*
    lblDestinatio = new Label();
    lblDestinatio.setLocation(106,97);
    lblDestinatio.setSize(119,25);
    lblDestinatio.setText("Destination Wor");
    getContentPane().add(lblDestinatio);
       */

    lblDestinatio = new Label();
    lblDestinatio.setLocation(106, 120);
    lblDestinatio.setSize(119, 25);
    lblDestinatio.setText("Destination Word:");
    getContentPane().add(lblDestinatio);

    lblWordSize = new Label();
    lblWordSize.setLocation(106, 27); // 106,120
    lblWordSize.setSize(119, 25);
    lblWordSize.setText("Word Size:");
    getContentPane().add(lblWordSize);

    tfWordSize = new TextField();
    tfWordSize.setLocation(224, 27); // 224,120
    tfWordSize.setSize(263, 25);
    tfWordSize.setBackground(new Color(-1));
    tfWordSize.setText("5");
    tfWordSize.setColumns(10);
    getContentPane().add(tfWordSize);

    tfSourc_6 = new TextField();
    tfSourc_6.setLocation(226, 120);
    tfSourc_6.setSize(263, 25);
    tfSourc_6.setBackground(new Color(-1));
    tfSourc_6.setText("");
    tfSourc_6.setColumns(10);
    getContentPane().add(tfSourc_6);

    lblFileNam = new Label();
    lblFileNam.setLocation(104, 0);
    lblFileNam.setSize(119, 25);
    lblFileNam.setText("FilePath:");
    getContentPane().add(lblFileNam);

    tfFilePat = new TextField();
    tfFilePat.setLocation(224, 0);
    tfFilePat.setSize(266, 25);
    tfFilePat.setBackground(new Color(-1));

    // OS Detection
    if (System.getProperty("os.name").startsWith("Windows")) {
      // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
      tfFilePat.setText("c:\\ics340\\words.txt");
      System.out.println("Detected Windows: " + System.getProperty("os.name"));
    } else {
      tfFilePat.setText("/Users/jasonedstrom/ics340/d1.txt");
      System.out.println("Detected Mac OS X: " + System.getProperty("os.name"));
    }

    tfFilePat.setColumns(10);
    getContentPane().add(tfFilePat);

    btLoadTextFiel = new JButton();
    btLoadTextFiel.setLocation(108, 50); // 108,27
    btLoadTextFiel.setSize(198, 32);
    btLoadTextFiel.setText("Load Words from Text Field");
    getContentPane().add(btLoadTextFiel);

    btLoadFil = new JButton();
    btLoadFil.setLocation(306, 50); // 306,27
    btLoadFil.setSize(183, 32);
    btLoadFil.setText("Load Words from File");
    getContentPane().add(btLoadFil);

    btFindPat = new JButton();
    btFindPat.setLocation(106, 160);
    btFindPat.setSize(384, 38);
    btFindPat.setText("Find Path");
    getContentPane().add(btFindPat);

    lblDictCoun = new JLabel();
    lblDictCoun.setLocation(108, 513);
    lblDictCoun.setSize(300, 27);
    lblDictCoun.setForeground(new Color(-65536));
    lblDictCoun.setText("Words in Dictionary = 0 words");
    getContentPane().add(lblDictCoun);

    lblIndexing1 = new JLabel();
    lblIndexing1.setLocation(107, 454);
    lblIndexing1.setSize(130, 27);
    lblIndexing1.setForeground(new Color(-16777216));
    lblIndexing1.setText("");
    getContentPane().add(lblIndexing1);

    lblFindPat = new JLabel();
    lblFindPat.setLocation(108, 540);
    lblFindPat.setSize(250, 27);
    lblFindPat.setForeground(new Color(-14646771));
    lblFindPat.setText("Time to find Path: 0 milliseconds");
    getContentPane().add(lblFindPat);

    lblCos = new JLabel();
    lblCos.setLocation(360, 540);
    lblCos.setSize(175, 27);
    lblCos.setForeground(new Color(-16777216));
    lblCos.setText("Cost of Path: 0.0");
    getContentPane().add(lblCos);

    lblProgres = new JLabel();
    lblProgres.setLocation(108, 484);
    lblProgres.setSize(371, 26);
    lblProgres.setForeground(new Color(-14646771));
    lblProgres.setText("Time to Build Graph: 0 milliseconds");
    getContentPane().add(lblProgres);

    testpanel = new JPanel();
    testpanel.setLocation(106, 200);
    testpanel.setSize(350, 200);
    testpanel.setForeground(new Color(-14646771));
    // testpanel.setText("Test Location");
    getContentPane().add(testpanel);

    btClear = new JButton();
    btClear.setLocation(355, 513);
    btClear.setSize(125, 25);
    btClear.setText("Clear Results");
    getContentPane().add(btClear);

    // add actionlisteners to buttons
    btFindPat.addActionListener(this);
    btLoadTextFiel.addActionListener(this);
    btLoadFil.addActionListener(this);
    btClear.addActionListener(this);

    setTitle("WordLadderGUI");
    setSize(500, 600);
    setVisible(true);
    setResizable(false);
  }
Beispiel #2
0
  public Configure() {
    int Width = 640;
    int Height = 480;
    cb = new Checkbox[128];
    final Frame f = new Frame("Configure gnu.io.rxtx.properties");
    String fileSep = System.getProperty("file.separator", "/");
    String devPath;
    if (fileSep.compareTo("/") != 0) {
      devPath = "COM";
    } else {
      devPath = "/dev/";
    }

    f.setBounds(100, 50, Width, Height);
    f.setLayout(new BorderLayout());
    p1 = new Panel();
    p1.setLayout(new GridLayout(16, 4));
    ActionListener l =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            {
              String res = e.getActionCommand();
              if (res.equals("Save")) {
                saveSpecifiedPorts();
              }
            }
          }
        };

    addCheckBoxes(devPath);
    TextArea t = new TextArea(EnumMessage, 5, 50, TextArea.SCROLLBARS_NONE);
    t.setSize(50, Width);
    t.setEditable(false);

    final Panel p2 = new Panel();
    p2.add(new Label("Port Name:"));
    TextField tf = new TextField(devPath, 8);
    tf.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addCheckBoxes(e.getActionCommand());
            f.setVisible(true);
          }
        });
    p2.add(tf);
    Checkbox Keep = new Checkbox("Keep Ports");
    p2.add(Keep);
    Button b[] = new Button[6];
    for (int j = 0, i = 4; i < 129; i *= 2, j++) {
      b[j] = new Button("1-" + i);
      b[j].addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              int k = Integer.parseInt(e.getActionCommand().substring(2));
              for (int x = 0; x < k; x++) {
                cb[x].setState(!cb[x].getState());
                f.setVisible(true);
              }
            }
          });
      p2.add(b[j]);
    }
    Button b1 = new Button("More");
    Button b2 = new Button("Save");
    b1.addActionListener(l);
    b2.addActionListener(l);
    p2.add(b1);
    p2.add(b2);
    f.add("South", p2);
    f.add("Center", p1);
    f.add("North", t);
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    f.setVisible(true);
  }
Beispiel #3
0
  public MainFrame(
      final Socket socket, String user, ObjectInputStream reader, ObjectOutputStream writer) {
    super("Main");

    frame = this;
    this.socket = socket;
    owner = user;
    Reader = reader;
    Writer = writer;

    screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frameSize = new Dimension(300, 510);
    setSize(frameSize);
    setLocation(screenSize.width / 2 - frameSize.width, (screenSize.height - frameSize.height) / 2);
    setBackground(Color.decode("#ccfffa"));
    setResizable(false);
    setLayout(null);

    // add Label "Online User List:"
    Label label1 = new Label("Online User List:");
    label1.setSize(200, 20);
    label1.setLocation(20, 40);
    add(label1);
    // add user list
    userList = new List(10, false);
    userList.setSize(260, 95);
    userList.setLocation(20, 60);
    add(userList);
    // add label "chat content:"
    Label label2 = new Label("Chat Content:");
    label2.setSize(200, 20);
    label2.setLocation(20, 160);
    add(label2);
    // add chat content
    textArea = new TextArea("", 18, 30, TextArea.SCROLLBARS_VERTICAL_ONLY);
    textArea.setBackground(Color.white);
    textArea.setEditable(false);
    textArea.setSize(260, 220);
    textArea.setLocation(20, 180);
    add(textArea);
    // add label "Send Message:"
    Label label3 = new Label("Send Message:");
    label3.setSize(200, 20);
    label3.setLocation(20, 405);
    add(label3);
    // add input textfield
    final TextField inputArea = new TextField();
    inputArea.setSize(205, 25);
    inputArea.setLocation(20, 425);
    add(inputArea);

    // add send button
    Button send = new Button("Send");
    send.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent arg0) {
            String text = inputArea.getText();
            try {
              Writer.writeObject(new MSG("MSG", text));
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            textArea.setText(textArea.getText().concat("[" + owner + "]:" + text + "\n"));
            inputArea.setText("");
          }
        });
    send.setSize(50, 25);
    send.setLocation(230, 425);
    add(send);

    // add button "Start Game"
    final Button btnGame = new Button("Start Game");
    btnGame.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!isGame) {
              setSize(460, 510);
              controlPanel = new ControlPanel(socket, Reader, Writer, frame, owner);
              controlPanel.setLocation(300, 60);
              add(controlPanel);
              isGame = true;
              try {
                Writer.writeObject(new MSG("REQLIST", ""));
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              btnGame.setLabel("End Game");
            } else {
              try {
                Writer.writeObject(new MSG("QUIT", ""));
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              setSize(300, 510);
              remove(controlPanel);
              isGame = false;
              btnGame.setLabel("Start Game");
            }
          }
        });
    btnGame.setSize(90, 25);
    btnGame.setLocation(65, 465);
    add(btnGame);

    // add button quit
    Button btnQuit = new Button("Exit");
    btnQuit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (isGame) {
              if (!controlPanel.canQuit) return;
              try {
                Writer.writeObject(new MSG("QUIT", ""));
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
              controlPanel.isHost = false;
              controlPanel.panelHost = null;
              controlPanel.panelHost = null;
              controlPanel.initPanelStart();
              controlPanel.panelStart.setSize(135, 420);
              controlPanel.panelStart.setLocation(0, 0);
              controlPanel.add(controlPanel.panelStart);
            }
            runFlag = false;
            if (socket != null) {
              try {
                Writer.writeObject(new MSG("QUT", ""));
                socket.close();
              } catch (IOException e) {
                // TODO Auto-generated catch block
                // e.printStackTrace();
              }
            }
            System.exit(0);
          }
        });
    btnQuit.setSize(55, 25);
    btnQuit.setLocation(175, 465);
    add(btnQuit);

    new ReceiveThread(Reader).start();
  }