コード例 #1
0
  /**
   * Init JWhiteBoard interface
   *
   * @throws Exception
   */
  public void go() throws Exception {
    if (!noChannel && !useState) channel.connect(groupName);
    mainFrame = new JFrame();
    mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    drawPanel = new DrawPanel(useState);
    drawPanel.setBackground(backgroundColor);
    subPanel = new JPanel();
    mainFrame.getContentPane().add("Center", drawPanel);
    clearButton = new JButton("Clean");
    clearButton.setFont(defaultFont);
    clearButton.addActionListener(this);
    leaveButton = new JButton("Exit");
    leaveButton.setFont(defaultFont);
    leaveButton.addActionListener(this);
    subPanel.add("South", clearButton);
    subPanel.add("South", leaveButton);
    mainFrame.getContentPane().add("South", subPanel);
    mainFrame.setBackground(backgroundColor);
    clearButton.setForeground(Color.blue);
    leaveButton.setForeground(Color.blue);
    mainFrame.pack();
    mainFrame.setLocation(15, 25);
    mainFrame.setBounds(new Rectangle(250, 250));

    if (!noChannel && useState) {
      channel.connect(groupName, null, stateTimeout);
    }
    mainFrame.setVisible(true);
  }
コード例 #2
0
  /** EdiDialog constructor comment. */
  public static void test() {
    JFrame frame = new JFrame();
    frame.addWindowListener(new CloseSaveWindowsListener());
    frame.setBackground(ConfigurableSystemSettings.backgroundColor.getAWTColor());
    frame.getContentPane().setLayout(new java.awt.BorderLayout());
    frame.setBounds(50, 50, 400, 400);
    frame.show();

    DialogNewElement dialog = new DialogNewElement(frame);
    dialog.show();
  }
コード例 #3
0
  public Fenetre() {

    frame = new JFrame();
    frame.setTitle("Gestion Sauvegarde Serveur");
    frame.setSize(700, 600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setIconImage(
        Toolkit.getDefaultToolkit().getImage(getClass().getResource("/go-home.png")));
    frame.setResizable(true);
    frame.setLocationRelativeTo(null);
    frame.setUndecorated(false);
    frame.setBackground(Color.white);
    frame.setContentPane(contentPane());
    frame.setVisible(true);
  }
コード例 #4
0
ファイル: Primary.java プロジェクト: nlindsley/Team-4x4
  Primary() {
    // Initial declarations, adding of listeners, and database linking.
    // Database link
    DBHookUp db = new DBHookUp();

    // Frame stuff
    frame = new JFrame("4 Byte Warrior");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBackground(Color.RED);
    frame.setResizable(false);
    // Panels
    main = new JPanel();
    scores = new JPanel();
    credits = new JPanel();
    story = new JPanel();
    tutorial = new JPanel();
    main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
    main.setBackground(Color.RED);
    main.setOpaque(true);
    scores.setLayout(new BorderLayout());
    scores.setBackground(Color.RED);
    scores.setOpaque(true);
    credits.setLayout(new BorderLayout());
    credits.setBackground(Color.RED);
    credits.setOpaque(true);
    // story.setLayout(new BoxLayout(story, BoxLayout.PAGE_AXIS));
    story.setLayout(new BorderLayout());
    story.setBackground(Color.RED);
    story.setOpaque(true);
    // tutorial.setLayout(new BoxLayout(tutorial, BoxLayout.PAGE_AXIS));
    tutorial.setLayout(new BorderLayout());
    tutorial.setBackground(Color.RED);
    tutorial.setOpaque(true);

    // Buttons
    start = new JButton("Go");
    start.addActionListener(this);
    start.setPreferredSize(new Dimension(125, 35));
    start.setAlignmentX(start.CENTER_ALIGNMENT);
    start.setBackground(Color.BLACK);
    start.setForeground(Color.WHITE);
    start.setHorizontalAlignment(SwingConstants.CENTER);
    cred = new JButton("Credits");
    cred.setPreferredSize(new Dimension(125, 35));
    cred.addActionListener(this);
    cred.setAlignmentX(cred.CENTER_ALIGNMENT);
    cred.setBackground(Color.BLACK);
    cred.setForeground(Color.WHITE);
    cred.setHorizontalAlignment(SwingConstants.CENTER);
    high = new JButton("High Scores");
    high.addActionListener(this);
    high.setPreferredSize(new Dimension(125, 35));
    high.setAlignmentX(high.CENTER_ALIGNMENT);
    high.setBackground(Color.BLACK);
    high.setForeground(Color.WHITE);
    high.setHorizontalAlignment(SwingConstants.CENTER);
    stor = new JButton("Next");
    stor.addActionListener(this);
    stor.setPreferredSize(new Dimension(100, 35));
    stor.setAlignmentX(stor.CENTER_ALIGNMENT);
    stor.setBackground(Color.BLACK);
    stor.setForeground(Color.WHITE);
    stor.setHorizontalAlignment(SwingConstants.CENTER);
    tutor = new JButton("Play");
    tutor.addActionListener(this);
    tutor.setPreferredSize(new Dimension(100, 35));
    tutor.setAlignmentX(tutor.CENTER_ALIGNMENT);
    tutor.setBackground(Color.BLACK);
    tutor.setForeground(Color.WHITE);
    returns1 = new JButton("Return");
    returns1.addActionListener(this);
    returns1.setPreferredSize(new Dimension(100, 35));
    returns1.setAlignmentX(returns1.CENTER_ALIGNMENT);
    returns1.setBackground(Color.BLACK);
    returns1.setForeground(Color.WHITE);
    returns1.setHorizontalAlignment(SwingConstants.CENTER);
    returns2 = new JButton("Return");
    returns2.addActionListener(this);
    returns2.setPreferredSize(new Dimension(100, 35));
    returns2.setAlignmentX(returns2.CENTER_ALIGNMENT);
    returns2.setBackground(Color.BLACK);
    returns2.setForeground(Color.WHITE);
    returns2.setHorizontalAlignment(SwingConstants.CENTER);
    returns3 = new JButton("Return");
    returns3.addActionListener(this);
    returns3.setPreferredSize(new Dimension(100, 35));
    returns3.setAlignmentX(returns3.CENTER_ALIGNMENT);
    returns3.setBackground(Color.BLACK);
    returns3.setForeground(Color.WHITE);
    returns3.setHorizontalAlignment(SwingConstants.CENTER);
    returns4 = new JButton("Return");
    returns4.addActionListener(this);
    returns4.setPreferredSize(new Dimension(100, 35));
    returns4.setAlignmentX(returns4.CENTER_ALIGNMENT);
    returns4.setBackground(Color.BLACK);
    returns4.setForeground(Color.WHITE);
    returns4.setHorizontalAlignment(SwingConstants.CENTER);

    // Text display
    theme = new JLabel();
    String text =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            300,
            "Binary was a land of peace, ruled by the good king Groshi. "
                + "One day, the Dark Knight and his armies descended upon "
                + "the kingdom, throwing it into chaos. The Dark Knight "
                + "killed Groshi and kidnapped his daughter Elsie. "
                + "Only one memember of the kingdom could hope to "
                + "save the kingdom...<br/><br/>"
                + "<font size = \"7\"> THE 4 BYTE WARRIOR </font>");
    theme.setText(text);
    theme.setHorizontalAlignment(JLabel.CENTER);
    theme.setVerticalAlignment(JLabel.CENTER);
    theme.setForeground(Color.WHITE);
    instruct = new JLabel();
    String instruction =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            200,
            "Z Key: Attack<br/>X Key: Cycle through inventory<br/>D-Pad: Movement<br/>A: Pause<br/><br/><br/>Defeat the enemeies to advance. Fight the bosses, get through the 8 worlds of Binary, and save Princess Elsie.");
    instruct.setText(instruction);
    instruct.setHorizontalAlignment(JLabel.CENTER);
    instruct.setVerticalAlignment(JLabel.CENTER);
    instruct.setForeground(Color.WHITE);
    String names =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            150, "Alexander Friebe<br/>Charles Heckel<br/>Nicholas Lindsley<br/>Ben McWerthy<br/>");
    people = new JLabel(names);
    people.setHorizontalAlignment(JLabel.CENTER);
    people.setVerticalAlignment(JLabel.CENTER);
    people.setForeground(Color.WHITE);
    String major =
        String.format(
            "<html><div style=\"width:%dpx;\"><center>%s</center></div><html>",
            150,
            "Computer Science<br/>Computer Engineering<br/>Computer Engineering<br/>Computer Science<br/>");
    majors = new JLabel(major);
    majors.setHorizontalAlignment(JLabel.CENTER);
    majors.setVerticalAlignment(JLabel.CENTER);
    majors.setForeground(Color.WHITE);
    String credi =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            150, "Credits");
    top = new JLabel(credi);
    top.setHorizontalAlignment(JLabel.CENTER);
    top.setVerticalAlignment(JLabel.CENTER);
    top.setForeground(Color.WHITE);
    scoresTop = new JLabel();
    String scTop =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            200, "High Scores for Enemies Killed");
    scoresTop.setText(scTop);
    scoresTop.setForeground(Color.WHITE);
    scoresTop.setHorizontalAlignment(JLabel.CENTER);
    scoresTop.setVerticalAlignment(JLabel.CENTER);
    JLabel dbScores = new JLabel();
    ArrayList<Integer> sc = db.getScores();
    System.out.println(sc.size());
    // System.out.println(sc.get(0));
    String actual =
        String.format(
            "<html><div style=\"width:%dpx;\"><center><font size = \"4\">%s</font></center></div><html>",
            100, sc.get(0) + "<br/>" + sc.get(1) + "<br/>" + sc.get(2) + "<br/>");
    dbScores.setText(actual);
    dbScores.setHorizontalAlignment(JLabel.CENTER);
    dbScores.setVerticalAlignment(JLabel.CENTER);
    dbScores.setForeground(Color.WHITE);

    // Additions to main
    mainButtons = new JPanel(new GridLayout(3, 1));
    mainButtons.add(start);
    mainButtons.add(high);
    mainButtons.add(cred);
    main.add(mainButtons);

    // Additions to credits
    credits.add(top, BorderLayout.PAGE_START);
    // credits.add(people, BorderLayout.LINE_START);
    // credits.add(majors, BorderLayout.LINE_END);
    JPanel middle = new JPanel(new GridLayout(1, 2));
    middle.add(people);
    middle.add(majors);
    middle.setBackground(Color.RED);
    JPanel bottom = new JPanel(new GridLayout(1, 1));
    bottom.add(returns2);
    bottom.setBackground(Color.RED);
    credits.add(middle, BorderLayout.CENTER);
    credits.add(bottom, BorderLayout.PAGE_END);

    // Additions to high scores
    scores.add(scoresTop, BorderLayout.PAGE_START);
    scores.add(dbScores, BorderLayout.CENTER);
    JPanel bot = new JPanel(new GridLayout(1, 1));
    bot.add(returns1);
    bot.setBackground(Color.RED);
    scores.add(bot, BorderLayout.PAGE_END);

    // Additions to story
    story.add(theme, BorderLayout.CENTER);
    buttons = new JPanel(new GridLayout(2, 1));
    buttons.setBackground(Color.RED);
    // buttons.setOpaque(true);
    buttons.add(stor);
    buttons.add(returns3);
    story.add(buttons, BorderLayout.PAGE_END);

    // Additions to tutorial
    JPanel tutButtons = new JPanel(new GridLayout(2, 1));
    tutorial.add(instruct, BorderLayout.CENTER);
    tutButtons.add(tutor);
    tutButtons.add(returns4);
    tutButtons.setBackground(Color.RED);
    tutorial.add(tutButtons, BorderLayout.PAGE_END);

    main.setBorder(new EmptyBorder(100, 150, 100, 150));
    bot.setBorder(new EmptyBorder(0, 150, 0, 150));
    // middle.setBorder(new EmptyBorder(0,150,0,150));
    bottom.setBorder(new EmptyBorder(0, 150, 0, 150));
    buttons.setBorder(new EmptyBorder(0, 150, 0, 150));
    tutButtons.setBorder(new EmptyBorder(0, 150, 0, 150));
    frame.add(main);

    frame
        .pack(); // critical to call before you make the window visible in order to make everything
                 // look right 100% of the time
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
  public Design() throws Exception {
    super.setBackground(Color.BLACK);
    this.setTitle("");
    con = getContentPane();
    con.setLayout(null);
    dim = tk.getDefaultToolkit().getScreenSize();
    this.setTitle("Customer Peer Login");

    l1 = new JLabel(new ImageIcon("plain.jpg"));
    l1.setBounds(0, 0, 400, 400);
    con.add(l1);
    l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black));

    title = new JLabel("CUSTOMER PEER LOGIN ");
    title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20));
    title.setForeground(Color.red);
    title.setBounds(80, 30, 300, 30);
    l1.add(title);

    l4 = new JLabel("CMACHINE NAME");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.BLUE);
    l4.setBounds(70, 100, 160, 20);
    //	l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green));

    l1.add(l4);
    jtf2 = new JTextField();
    jtf2.setBounds(250, 100, 100, 20);
    jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf2);

    l2 = new JLabel("CUSER LOGIN");
    l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l2.setForeground(Color.blue);
    l2.setBounds(70, 150, 120, 20);
    l1.add(l2);

    jtf1 = new JTextField();
    jtf1.setBounds(250, 150, 100, 20);
    jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf1);

    l3 = new JLabel("CPASSWORD");
    l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l3.setForeground(Color.blue);
    l3.setBounds(70, 200, 120, 20);
    l1.add(l3);

    jptf1 = new JPasswordField();
    jptf1.setBounds(250, 200, 100, 20);
    jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jptf1);

    JLabel l4 = new JLabel("DAgent");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.blue);
    l4.setBounds(70, 250, 120, 20);
    l1.add(l4);

    box = new JComboBox();
    box.setBounds(250, 250, 100, 20);
    box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));
    l1.add(box);

    b2 = new JButton("Register");
    b2.setBounds(50, 300, 100, 20);
    l1.add(b2);
    b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    b3 = new JButton("Login");
    b3.setBounds(150, 300, 100, 20);
    b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));
    l1.add(b3);

    b1 = new JButton("Cancel");
    b1.setBounds(250, 300, 100, 20);
    b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    l1.add(b1);

    b1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            dispose();
          }
        });

    try {

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      conn = DriverManager.getConnection("jdbc:odbc:agent");

    } catch (Exception exp) {

    }

    try {
      Statement satem = conn.createStatement();
      ResultSet rsatem = satem.executeQuery("select * from Dagent");
      while (rsatem.next()) {
        String namem = rsatem.getString("uname");
        box.addItem(namem);
      }

    } catch (Exception expo1) {

    }

    b2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String dname = box.getSelectedItem().toString();
            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {
              exp.printStackTrace();
            }

            try {
              packet p = new packet();
              p.setaction("Creg");
              p.setCuser(username);
              p.setCpass(password);
              p.setCmname(mechine);
              p.setCDpeer(dname);
              Socket soc = new Socket(servermachine, porte);
              ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
              out.writeObject(p);
              ObjectInputStream in = new ObjectInputStream(soc.getInputStream());
              packet rpac = (packet) in.readObject();
              if (rpac.getaction().equals("ok")) {

                JOptionPane.showMessageDialog(null, "Sucessfully Registered");

                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");

              } else {

                JOptionPane.showMessageDialog(null, "Already Registered");
                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String Dname = box.getSelectedItem().toString();

            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + Dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {

            }

            try {

              packet p1 = new packet();
              p1.setaction("clogin");
              p1.setCuser(username);
              p1.setCpass(password);
              p1.setCmname(mechine);
              p1.setCDpeer(Dname);
              Socket soc1 = new Socket(servermachine, porte);
              ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream());
              out1.writeObject(p1);
              ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream());
              packet rpac1 = (packet) in1.readObject();
              if (rpac1.getaction().equals("ok")) {
                int port1 = 0;
                try {

                  int portm = rpac1.getCport();
                  System.out.println("XXXXXXX" + portm);
                  //	JOptionPane.showMessageDialog(null,"Sucessfully Started");

                  new Listen(portm);
                  new process(username, portm);
                  dispose();
                } catch (Exception exp) {
                }
              } else {
                JOptionPane.showMessageDialog(
                    null, "Enter valid username and password", "Server reply", 2);
                jtf1.setText("");
                jtf2.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    setSize(400, 400);
    show();
    setLocation(150, 100);
    setResizable(false);
  }