Ejemplo n.º 1
0
  public static void main(String args[]) {

    JFrame f = new JFrame("JPasswordField3");
    Container contentPane = f.getContentPane();
    contentPane.setLayout(new BorderLayout());

    JPanel p1 = new JPanel();
    // p1.setLayout(new GridLayout(4,2));
    p1.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST; // 设定Layout的位置
    gbc.insets = new Insets(2, 2, 2, 2); // 设定与边界的距离(上,左,下,右)

    p1.setBorder(BorderFactory.createTitledBorder("您的基本数据"));
    JLabel l1 = new JLabel("姓名:");
    JLabel l2 = new JLabel("性别:");
    JLabel l3 = new JLabel("身高:");
    JLabel l4 = new JLabel("体重:");
    JPasswordField t1 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(10), "", 10);
    JPasswordField t2 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(1), "", 2);
    JPasswordField t3 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5);
    JPasswordField t4 = new JPasswordField(new JPasswordField3_OnlyNumberDocument(5), "", 5);

    gbc.gridy = 1;
    gbc.gridx = 0;
    p1.add(l1, gbc);
    gbc.gridx = 1;
    p1.add(t1, gbc);
    gbc.gridy = 2;
    gbc.gridx = 0;
    p1.add(l2, gbc);
    gbc.gridx = 1;
    p1.add(t2, gbc);
    gbc.gridy = 3;
    gbc.gridx = 0;
    p1.add(l3, gbc);
    gbc.gridx = 1;
    p1.add(t3, gbc);
    gbc.gridy = 4;
    gbc.gridx = 0;
    p1.add(l4, gbc);
    gbc.gridx = 1;
    p1.add(t4, gbc);

    contentPane.add(p1);
    f.pack();
    f.show();
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
Ejemplo n.º 2
0
  public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {

    JFrame jf = new JFrame();

    AttributesPanel colpal = new AttributesPanel();
    colpal.setEntity(new FrameFact("hola"));
    colpal.setEntity(new FrameFact("hola"));
    jf.getContentPane().add(colpal);
    jf.pack();
    jf.show();
    jf.pack();
  }
Ejemplo n.º 3
0
 public static void main(String[] args) {
   JFrame frame = new JFrame("Cwiczenie5_4");
   Container cp = frame.getContentPane();
   Cwiczenie5_4 Cwiczenie5_4 = new Cwiczenie5_4();
   cp.add(Cwiczenie5_4);
   frame.addKeyListener(Cwiczenie5_4.bar);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setResizable(false);
   frame.setLocation(300, 300);
   frame.pack();
   frame.show();
   Cwiczenie5_4.startGame();
 }
Ejemplo n.º 4
0
  public static void main(String arg[]) {

    JFrame f = new JFrame("SimpleBorder");
    Container content = f.getContentPane();
    JButton b = new JButton();
    b.setBorder(BorderFactory.createLineBorder(Color.blue, 10));
    content.add(b);
    f.setSize(200, 150);
    f.show();

    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
 public static void main(String s[]) {
   if (s.length > 0) j2kfilename = s[0];
   else j2kfilename = "girl";
   System.out.println(j2kfilename);
   isApplet = false;
   JFrame f = new JFrame("ImageViewer");
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       });
   JApplet applet = new ImageViewer();
   f.getContentPane().add("Center", applet);
   applet.init();
   f.pack();
   f.setSize(new Dimension(550, 550));
   f.show();
 }
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }

    Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll");
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("Actions");
    menu.add(action);
    menubar.add(menu);

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);
    toolbar.setFloatable(true);
    toolbar.add(action);

    JPanel contents = new JPanel();

    String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5            "};
    JList list = new JList(listData);
    contents.add(new JScrollPane(list));

    JTree tree = new JTree();
    tree.setVisibleRowCount(10);
    contents.add(new JScrollPane(tree));

    JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10));
    table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight()));
    contents.add(new JScrollPane(table));
    contents.add(new JPanel());

    JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menubar);
    frame.getContentPane().add(contents);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    frame.pack();
    frame.show();
  }
Ejemplo n.º 7
0
  /** Returns a DebugGraphics for use in buffering window. */
  private Graphics debugGraphics() {
    DebugGraphics debugGraphics;
    DebugGraphicsInfo info = info();
    JFrame debugFrame;

    if (info.debugFrame == null) {
      info.debugFrame = new JFrame();
      info.debugFrame.setSize(500, 500);
    }
    debugFrame = info.debugFrame;
    debugFrame.show();
    debugGraphics = new DebugGraphics(debugFrame.getGraphics());
    debugGraphics.setFont(getFont());
    debugGraphics.setColor(getColor());
    debugGraphics.translate(xOffset, yOffset);
    debugGraphics.setClip(getClipBounds());
    if (debugFlash()) {
      debugGraphics.setDebugOptions(FLASH_OPTION);
    }
    return debugGraphics;
  }
Ejemplo n.º 8
0
  public JList7() {
    JFrame f = new JFrame("JList");
    Container contentPane = f.getContentPane();
    contentPane.setLayout(new BorderLayout());
    label = new JLabel();

    list = new JList(s);
    list.setVisibleRowCount(5);
    list.setBorder(BorderFactory.createTitledBorder("您最喜欢到哪个国家玩呢?"));
    list.addListSelectionListener(this);

    contentPane.add(label, BorderLayout.NORTH);
    contentPane.add(new JScrollPane(list), BorderLayout.CENTER);
    f.pack();
    f.show();
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
Ejemplo n.º 9
0
    public static void main(String[] args) {
      // Create some components and a FontChooser dialog
      final JFrame frame = new JFrame("demo");
      final JButton button = new JButton("Push Me!");
      final FontChooser chooser = new FontChooser(frame);

      // Handle button clicks
      button.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              // Pop up the dialog
              chooser.show();
              // Get the user's selection
              Font font = chooser.getSelectedFont();
              // If not cancelled, set the button font
              if (font != null) button.setFont(font);
            }
          });

      // Display the demo
      frame.getContentPane().add(button);
      frame.setSize(200, 100);
      frame.show();
    }
Ejemplo n.º 10
0
  public static void main(String args[]) {

    JFrame frame = new JFrame("Drag Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    final JLabel label = new JLabel();
    //    Icon icon = new ImageIcon("/home/j2ee/Desktop/war.103.gif");
    //    label.setIcon(icon);
    label.setTransferHandler(new ImageSelection());

    MouseListener mouseListener =
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
          }
        };
    label.addMouseListener(mouseListener);

    JScrollPane pane = new JScrollPane(label);
    contentPane.add(pane, BorderLayout.CENTER);

    JButton copy = new JButton("Copy");
    copy.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            // fire TransferHandler's built-in copy
            // action with a new actionEvent having
            // "label" as the source
            Action copyAction = TransferHandler.getCopyAction();
            copyAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) copyAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JButton clear = new JButton("Clear");
    clear.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            label.setIcon(null);
          }
        });

    JButton paste = new JButton("Paste");
    paste.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            // use TransferHandler's built-in
            // paste action
            Action pasteAction = TransferHandler.getPasteAction();
            pasteAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) pasteAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JPanel p = new JPanel();
    p.add(copy);
    p.add(clear);
    p.add(paste);
    contentPane.add(p, BorderLayout.SOUTH);

    frame.setSize(300, 300);
    frame.show();
  }
Ejemplo n.º 11
0
 public static void main(String[] args) {
   JFrame w = new Main();
   w.show();
 }
Ejemplo n.º 12
0
 /** Test program */
 public static void main(String[] args) {
   JFrame f = new QuitableJFrame("Test", 300, 300);
   // We'll handle closing, so...
   f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   f.show();
 }
Ejemplo n.º 13
0
 public void show() {
   wizardComponents.updateComponents();
   this.setSize(600, 600);
   Utilities.centerComponentOnScreen(this);
   super.show();
 }
Ejemplo n.º 14
0
 public static void main(String[] args) {
   JFrame frame = new QueryDBFrame();
   frame.show();
 }
Ejemplo n.º 15
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();
  }