Пример #1
0
  // function to center the frame
  public static void center(JFrame jfrm) {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int width = jfrm.getSize().width;
    int height = jfrm.getSize().height;

    int x = (dim.width - width) / 2;
    int y = (dim.height - height) / 2;

    jfrm.setLocation(x, y);
  }
Пример #2
0
 public static void main(String[] args) {
   TableModelDemo applet = new TableModelDemo();
   JFrame frame = new JFrame();
   // EXIT_ON_CLOSE == 3
   frame.setDefaultCloseOperation(3);
   frame.setTitle("TableModelDemo");
   frame.getContentPane().add(applet, BorderLayout.CENTER);
   applet.init();
   applet.start();
   frame.setSize(500, 220);
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   frame.setLocation(
       (d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
   frame.setVisible(true);
 }
Пример #3
0
 public PlayGamePanel(JFrame frame, BoardConfiguration bc) {
   this.bc = bc;
   this.frame = frame;
   ImageIcon icon = new ImageIcon("ent.jpg");
   this.image = icon.getImage();
   this.one = new TransparentButton("1 Player");
   this.two = new TransparentButton("2 Players");
   this.three = new TransparentButton("3 Players");
   this.four = new TransparentButton("4 Players");
   this.setSize(frame.getSize());
   this.setLocation(0, 0);
   this.setLayout(null);
   one.setBounds(450, 140, 200, 40);
   two.setBounds(450, 200, 200, 40);
   three.setBounds(450, 260, 200, 40);
   four.setBounds(450, 320, 200, 40);
   this.add(one);
   this.add(two);
   this.add(three);
   this.add(four);
   this.back = new TransparentButton("Back");
   back.setBounds(450, 380, 200, 40);
   this.add(back);
   this.one.setFont(new Font("calibri", Font.ITALIC, 30));
   this.two.setFont(new Font("calibri", Font.ITALIC, 30));
   this.three.setFont(new Font("calibri", Font.ITALIC, 30));
   this.four.setFont(new Font("calibri", Font.ITALIC, 30));
   this.back.setFont(new Font("calibri", Font.ITALIC, 30));
   this.one.addMouseListener(this);
   this.two.addMouseListener(this);
   this.three.addMouseListener(this);
   this.four.addMouseListener(this);
   this.back.addMouseListener(this);
   this.back.setForeground(Color.red);
 }
  public BaseballController() {

    // Connect to Database

    try {
      dataBase = new DBWrapper();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    screen = new JFrame("Math Baseball");
    screen.setExtendedState(Frame.MAXIMIZED_BOTH);
    screen.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    inputManager = new InputManager(screen);
    createGameActions();
    loginPanel = new BackGroundPanel();
    loginPanel.setPreferredSize(screen.getSize());
    loginPanel.setOpaque(false);
    loginPanel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;

    uNameField = new JTextField();
    TextPrompt uText = new TextPrompt("Username", uNameField, TextPrompt.Show.FOCUS_LOST);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 1;
    loginPanel.add(uNameField, constraints);

    pWordField = new JPasswordField();
    TextPrompt pText = new TextPrompt("Password", pWordField, TextPrompt.Show.FOCUS_LOST);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 2;
    loginPanel.add(pWordField, constraints);

    isTeacher = new JRadioButton("Teacher");
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 3;
    loginPanel.add(isTeacher, constraints);

    loginButton = createButton("loginButton", "To Login");
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 4;
    loginPanel.add(loginButton, constraints);

    registerButton = new JButton("Register");
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 5;
    constraints.anchor = GridBagConstraints.PAGE_END;
    loginPanel.add(registerButton, constraints);

    Container contentPane = screen.getContentPane();
    // make sure the content pane is transparent
    if (contentPane instanceof JComponent) {
      ((JComponent) contentPane).setOpaque(false);
    }
    // add components to the screen's content pane
    contentPane.add(loginPanel);
    screen.setVisible(true);
    screen.validate();
    // screen.repaint();
    // add listeners
    isTeacher.addActionListener(this);
    loginButton.addActionListener(this);
    registerButton.addActionListener(this);
  }
Пример #5
0
  //
  // Build installer window
  //
  public static void showInstallerWindow() {
    _installerFrame = new JFrame(Config.getWindowTitle());

    Container cont = _installerFrame.getContentPane();
    cont.setLayout(new BorderLayout());

    // North pane
    Box topPane = new Box(BoxLayout.X_AXIS);
    JLabel title = new JLabel(Config.getWindowHeading());
    Font titleFont = new Font("SansSerif", Font.BOLD, 22);
    title.setFont(titleFont);
    title.setForeground(Color.black);

    // Create Sun logo
    URL urlLogo = Main.class.getResource(Config.getWindowLogo());
    Image img = Toolkit.getDefaultToolkit().getImage(urlLogo);
    MediaTracker md = new MediaTracker(_installerFrame);
    md.addImage(img, 0);
    try {
      md.waitForAll();
    } catch (Exception ioe) {
      Config.trace(ioe.toString());
    }
    if (md.isErrorID(0)) Config.trace("Error loading image");
    Icon sunLogo = new ImageIcon(img);
    JLabel logoLabel = new JLabel(sunLogo);
    logoLabel.setOpaque(true);
    topPane.add(topPane.createHorizontalStrut(5));
    topPane.add(title);
    topPane.add(topPane.createHorizontalGlue());
    topPane.add(logoLabel);
    topPane.add(topPane.createHorizontalStrut(5));

    // West Pane
    Box westPane = new Box(BoxLayout.X_AXIS);
    westPane.add(westPane.createHorizontalStrut(10));

    // South Pane
    Box bottomPane = new Box(BoxLayout.X_AXIS);
    bottomPane.add(bottomPane.createHorizontalGlue());
    JButton abortButton = new JButton(Config.getWindowAbortButton());
    abortButton.setMnemonic(Config.getWindowAbortMnemonic());
    bottomPane.add(abortButton);
    bottomPane.add(bottomPane.createHorizontalGlue());
    bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));

    // Center Pane
    Box centerPane = new Box(BoxLayout.Y_AXIS);
    JLabel hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);
    _stepLabels = new JLabel[5];
    for (int i = 0; i < _stepLabels.length; i++) {
      _stepLabels[i] = new JLabel(Config.getWindowStep(i));
      _stepLabels[i].setEnabled(false);
      centerPane.add(_stepLabels[i]);

      // install label's length will expand,so set a longer size.
      if (i == STEP_INSTALL) {
        Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize();
        _stepLabels[i].setPreferredSize(dim);
      }
    }
    hidden = new JLabel(Config.getWindowHiddenLabel());
    hidden.setVisible(false);
    centerPane.add(hidden);

    // Setup box layout
    cont.add(topPane, "North");
    cont.add(westPane, "West");
    cont.add(bottomPane, "South");
    cont.add(centerPane, "Center");

    _installerFrame.pack();
    Dimension dim = _installerFrame.getSize();

    // hard code to ensure title is completely visible on Sol/lin.
    if (dim.width < 400) {
      dim.width = 400;
      _installerFrame.setSize(dim);
    }

    Rectangle size = _installerFrame.getBounds();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    size.width = Math.min(screenSize.width, size.width);
    size.height = Math.min(screenSize.height, size.height);
    // Put window at 1/4, 1/4 of screen resoluion
    _installerFrame.setBounds(
        (screenSize.width - size.width) / 4,
        (screenSize.height - size.height) / 4,
        size.width,
        size.height);

    // Setup event listners
    _installerFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent we) {
            installFailed("Window closed", null);
          }
        });

    abortButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            installFailed("Abort pressed", null);
          }
        });

    // Show window
    _installerFrame.show();
  }
  void main() {

    CommonSwing.setDefaultColor();

    fMain = new JFrame("HSQL Database Manager");

    // (ulrivo): An actual icon.
    fMain.getContentPane().add(createToolBar(), "North");
    fMain.setIconImage(CommonSwing.getIcon());
    fMain.addWindowListener(this);

    JMenuBar bar = new JMenuBar();

    // used shortcuts: CERGTSIUDOLM
    String fitems[] = {
      "-Connect...", "--", "-Open Script...", "-Save Script...", "-Save Result...", "--", "-Exit"
    };

    addMenu(bar, "File", fitems);

    String vitems[] = {"RRefresh Tree", "--", "GResults in Grid", "TResults in Text"};

    addMenu(bar, "View", vitems);

    String sitems[] = {
      "SSELECT",
      "IINSERT",
      "UUPDATE",
      "DDELETE",
      "---",
      "-CREATE TABLE",
      "-DROP TABLE",
      "-CREATE INDEX",
      "-DROP INDEX",
      "--",
      "-CHECKPOINT",
      "-SCRIPT",
      "-SET",
      "-SHUTDOWN",
      "--",
      "-Test Script"
    };

    addMenu(bar, "Command", sitems);

    mRecent = new JMenu("Recent");

    bar.add(mRecent);

    String soptions[] = {
      "-AutoCommit on",
      "-AutoCommit off",
      "OCommit",
      "LRollback",
      "--",
      "-Disable MaxRows",
      "-Set MaxRows to 100",
      "--",
      "-Logging on",
      "-Logging off",
      "--",
      "-Insert test data"
    };

    addMenu(bar, "Options", soptions);

    String stools[] = {"-Dump", "-Restore", "-Transfer"};

    addMenu(bar, "Tools", stools);
    fMain.setJMenuBar(bar);
    initGUI();

    sRecent = new String[iMaxRecent];

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = fMain.getSize();

    // (ulrivo): full size on screen with less than 640 width
    if (d.width >= 640) {
      fMain.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2);
    } else {
      fMain.setLocation(0, 0);
      fMain.setSize(d);
    }

    fMain.show();

    // (ulrivo): load query from command line
    if (defScript != null) {
      if (defDirectory != null) {
        defScript = defDirectory + File.separator + defScript;
      }

      // if insert stmet is thousands of records...skip showing it
      // as text.  Too huge.
      StringBuffer buf = new StringBuffer();

      ifHuge = DatabaseManagerCommon.readFile(defScript);

      if (4096 <= ifHuge.length()) {
        buf.append("This huge file cannot be edited. Please execute\n");
        txtCommand.setText(buf.toString());
      } else {
        txtCommand.setText(ifHuge);
      }
    }

    txtCommand.requestFocus();
  }