// create and position GUI components; register event handlers private void createUserInterface() { // get content pane for attaching GUI components Container contentPane = getContentPane(); // enable explicit positioning of GUI components contentPane.setLayout(null); // set up principalJLabel principalJLabel = new JLabel(); principalJLabel.setBounds(16, 16, 56, 24); principalJLabel.setText("Principal:"); contentPane.add(principalJLabel); // set up principalJTextField principalJTextField = new JTextField(); principalJTextField.setBounds(100, 16, 100, 24); principalJTextField.setHorizontalAlignment(JTextField.RIGHT); contentPane.add(principalJTextField); // set up interestRateJLabel interestRateJLabel = new JLabel(); interestRateJLabel.setBounds(16, 56, 80, 24); interestRateJLabel.setText("Interest rate:"); contentPane.add(interestRateJLabel); // set up interestRateJTextField interestRateJTextField = new JTextField(); interestRateJTextField.setBounds(100, 56, 100, 24); interestRateJTextField.setHorizontalAlignment(JTextField.RIGHT); contentPane.add(interestRateJTextField); // set up yearsJLabel yearsJLabel = new JLabel(); yearsJLabel.setBounds(16, 96, 48, 24); yearsJLabel.setText("Years:"); contentPane.add(yearsJLabel); // set up yearsJSpinner yearsJSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 10, 1)); yearsJSpinner.setBounds(100, 96, 100, 24); contentPane.add(yearsJSpinner); // set up yearlyBalanceJLabel yearlyBalanceJLabel = new JLabel(); yearlyBalanceJLabel.setBounds(16, 136, 150, 24); yearlyBalanceJLabel.setText("Yearly account balance:"); contentPane.add(yearlyBalanceJLabel); // set up yearlyBalanceJTextArea yearlyBalanceJTextArea = new JTextArea(); yearlyBalanceJTextArea.setEditable(false); // set up yearlyBalanceJScrollPane yearlyBalanceJScrollPane = new JScrollPane(yearlyBalanceJTextArea); yearlyBalanceJScrollPane.setBounds(16, 160, 300, 92); contentPane.add(yearlyBalanceJScrollPane); // set up calculateJButton calculateJButton = new JButton(); calculateJButton.setBounds(216, 16, 100, 24); calculateJButton.setText("Calculate"); contentPane.add(calculateJButton); calculateJButton.addActionListener( new ActionListener() // anonymous inner class { // event handler called when calculateJButton is clicked public void actionPerformed(ActionEvent event) { calculateJButtonActionPerformed(event); } } // end anonymous inner class ); // end call to addActionListener // set properties of application's window setTitle("Interest Calculator"); // set title bar text setSize(340, 296); // set window size setVisible(true); // display window } // end method createUserInterface
@SuppressWarnings("deprecation") NPCPane(SpritesNPCManager mgr, int NPCIndex) { myIndex = NPCIndex; setBorder(new TitledBorder(null, "NPC", TitledBorder.LEADING, TitledBorder.TOP, null, null)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); lblSpriteSet = new JLabel("Spriteset:"); add(lblSpriteSet); lblSpriteSet.setBounds(10, 38, lblSpriteSet.getText().length() * 8, 16); Rectangle r = lblSpriteSet.getBounds(); txtSpriteSet = new JSpinner(new SpinnerNumberModel(0, 0, 255, 1)); txtSpriteSet.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { Save(MapIO.loadedMap.mapNPCManager); } }); add(txtSpriteSet); txtSpriteSet.setBounds(90, 38, 87, 16); // txtSpriteSet.disable(); lblBehavior1 = new JLabel("Behavior1:"); add(lblBehavior1); lblBehavior1.setBounds(10, 54, lblBehavior1.getText().length() * 8, 16); r = lblBehavior1.getBounds(); txtBehavior1 = new JTextField(); txtBehavior1.setColumns(2); add(txtBehavior1); txtBehavior1.setBounds(90, 54, 32, 16); lblBehavior2 = new JLabel("Behavior2:"); add(lblBehavior2); lblBehavior2.setBounds(10, 70, lblBehavior2.getText().length() * 8, 16); r = lblBehavior2.getBounds(); txtBehavior2 = new JTextField(); txtBehavior2.setColumns(2); add(txtBehavior2); txtBehavior2.setBounds(90, 70, 64, 16); lblIsTrainer = new JLabel("Is a Trainer:"); add(lblIsTrainer); lblIsTrainer.setBounds(10, 86, lblIsTrainer.getText().length() * 8, 16); r = lblIsTrainer.getBounds(); chkIsTrainer = new JCheckBox(); add(chkIsTrainer); chkIsTrainer.setBounds(114, 86, 32, 16); lblTrainerLOS = new JLabel("TrainerLOS:"); add(lblTrainerLOS); lblTrainerLOS.setBounds(10, 102, lblTrainerLOS.getText().length() * 8, 16); r = lblTrainerLOS.getBounds(); txtTrainerLOS = new JTextField(); txtTrainerLOS.setColumns(3); add(txtTrainerLOS); txtTrainerLOS.setBounds(90, 102, 32, 16); lbliFlag = new JLabel("NPC Flag:"); add(lbliFlag); lbliFlag.setBounds(10, 128, 88, 16); txtiFlag = new JTextField(); txtiFlag.setColumns(4); add(txtiFlag); txtiFlag.setText("0"); txtiFlag.setBounds(90, 128, 32, 16); lblScript = new JLabel("NPC Script Pointer:"); add(lblScript); lblScript.setBounds(10, 150, 88, 16); txtScript = new JTextField(); txtScript.setColumns(9); add(txtScript); txtScript.setText("0"); txtScript.setBounds(90, 150, 32, 16); JButton btnSave = new JButton("Save"); btnSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Save(MapIO.loadedMap.mapNPCManager); } }); add(btnSave); btnSave.setBounds(55, 163, 89, 23); Load(mgr, NPCIndex); }
private void jbInit() throws Exception { final JLabel textAndFont = new JLabel(Messages.getMessage("PdfViewerLabel.TextAndFont")); textAndFont.setFont(new java.awt.Font("Dialog", Font.BOLD, 14)); textAndFont.setDisplayedMnemonic('0'); textAndFont.setBounds(new Rectangle(13, 13, 220, 26)); final JLabel left = new JLabel(Messages.getMessage("PdfViewerLabel.Left")); left.setBounds(new Rectangle(130, 40, 50, 23)); final JLabel center = new JLabel(Messages.getMessage("PdfViewerLabel.Center")); center.setBounds(new Rectangle(300, 40, 50, 23)); final JLabel right = new JLabel(Messages.getMessage("PdfViewerLabel.Right")); right.setBounds(new Rectangle(475, 40, 50, 23)); final JLabel header = new JLabel(Messages.getMessage("PdfViewerLabel.Header")); header.setBounds(new Rectangle(20, 60, 90, 23)); final JLabel footer = new JLabel(Messages.getMessage("PdfViewerLabel.Footer")); footer.setBounds(new Rectangle(20, 90, 50, 23)); leftHeaderBox.setBounds(new Rectangle(85, 60, 133, 23)); centerHeaderBox.setBounds(new Rectangle(250, 60, 133, 23)); rightHeaderBox.setBounds(new Rectangle(425, 60, 133, 23)); leftFooterBox.setBounds(new Rectangle(85, 90, 133, 23)); centerFooterBox.setBounds(new Rectangle(250, 90, 133, 23)); rightFooterBox.setBounds(new Rectangle(425, 90, 133, 23)); final JLabel font = new JLabel(Messages.getMessage("PdfViewerLabel.Font")); font.setBounds(new Rectangle(20, 120, 75, 23)); fontsList.setBounds(new Rectangle(85, 120, 150, 23)); fontsList.setSelectedItem("Helvetica"); final JLabel size = new JLabel(Messages.getMessage("PdfViewerLabel.Size")); size.setBounds(new Rectangle(250, 120, 50, 23)); fontSize.setBounds(new Rectangle(290, 120, 50, 23)); final JLabel color = new JLabel(Messages.getMessage("PdfViewerLabel.Color")); color.setBounds(new Rectangle(360, 120, 50, 23)); colorBox.setBackground(Color.black); colorBox.setOpaque(true); colorBox.setBounds(new Rectangle(410, 120, 23, 23)); final JButton chooseColor = new JButton(Messages.getMessage("PdfViewerButton.ChooseColor")); chooseColor.setBounds(new Rectangle(450, 120, 160, 23)); chooseColor.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { colorBox.setBackground( JColorChooser.showDialog(null, "Color", colorBox.getBackground())); } }); tagsList.setText( "You may use the following\n" + "tags as part of the text.\n\n" + "<d> - Date in short format\n" + "<D> - Date in long format\n" + "<t> - Time in 12-hour format\n" + "<T> - Time in 24-hour format\n" + "<f> - Filename\n" + "<F> - Full path filename\n" + "<p> - Current page number\n" + "<P> - Total number of pages"); tagsList.setOpaque(false); tagsList.setBounds(350, 160, 200, 210); final JLabel margins = new JLabel(Messages.getMessage("PdfViewerLabel.Margins")); margins.setFont(new java.awt.Font("Dialog", Font.BOLD, 14)); margins.setDisplayedMnemonic('0'); margins.setBounds(new Rectangle(13, 150, 220, 26)); final JLabel leftRight = new JLabel(Messages.getMessage("PdfViewerLabel.LeftAndRight")); leftRight.setBounds(new Rectangle(20, 185, 90, 23)); leftRightBox.setBounds(new Rectangle(100, 185, 70, 23)); final JLabel topBottom = new JLabel(Messages.getMessage("PdfViewerLabel.TopAndBottom")); topBottom.setBounds(new Rectangle(180, 185, 120, 23)); topBottomBox.setBounds(new Rectangle(300, 185, 70, 23)); pageRangeLabel.setText(Messages.getMessage("PdfViewerPageRange.text")); pageRangeLabel.setBounds(new Rectangle(13, 220, 400, 26)); printAll.setText(Messages.getMessage("PdfViewerRadioButton.All")); printAll.setBounds(new Rectangle(23, 250, 75, 22)); printCurrent.setText(Messages.getMessage("PdfViewerRadioButton.CurrentPage")); printCurrent.setBounds(new Rectangle(23, 270, 100, 22)); printCurrent.setSelected(true); printPages.setText(Messages.getMessage("PdfViewerRadioButton.Pages")); printPages.setBounds(new Rectangle(23, 292, 70, 22)); pagesBox.setBounds(new Rectangle(95, 292, 230, 22)); pagesBox.addKeyListener( new KeyListener() { @Override public void keyPressed(final KeyEvent arg0) {} @Override public void keyReleased(final KeyEvent arg0) { if (pagesBox.getText().isEmpty()) { printCurrent.setSelected(true); } else { printPages.setSelected(true); } } @Override public void keyTyped(final KeyEvent arg0) {} }); final JTextArea pagesInfo = new JTextArea(Messages.getMessage("PdfViewerMessage.PageNumberOrRangeLong")); pagesInfo.setBounds(new Rectangle(23, 320, 620, 40)); pagesInfo.setOpaque(false); this.add(printAll, null); this.add(printCurrent, null); this.add(printPages, null); this.add(pagesBox, null); this.add(pagesInfo, null); this.add(left, null); this.add(center, null); this.add(right, null); this.add(header, null); this.add(footer, null); this.add(leftHeaderBox, null); this.add(centerHeaderBox, null); this.add(rightHeaderBox, null); this.add(leftFooterBox, null); this.add(centerFooterBox, null); this.add(rightFooterBox, null); this.add(font, null); this.add(fontsList, null); this.add(size, null); this.add(fontSize, null); this.add(color, null); this.add(colorBox, null); this.add(chooseColor, null); this.add(margins, null); this.add(leftRight, null); this.add(leftRightBox, null); this.add(topBottom, null); this.add(topBottomBox, null); this.add(textAndFont, null); this.add(changeButton, null); this.add(pageRangeLabel, null); // this.add(tagsList, null); this.add(jToggleButton2, null); this.add(jToggleButton3, null); buttonGroup1.add(printAll); buttonGroup1.add(printCurrent); buttonGroup1.add(printPages); }
ModiPanel(MemberPane mp, BusinessPane bp) { this.member_pane = mp; this.busi_pane = bp; setLayout(null); add(member_title); member_title.setBounds(20, 10, 80, 20); add(member_id); member_id.setBounds(20, 35, 80, 20); add(member_name); member_name.setBounds(20, 60, 80, 20); add(member_tele); member_tele.setBounds(20, 85, 80, 20); add(member_level); member_level.setBounds(20, 110, 80, 20); add(member_bal); member_bal.setBounds(20, 135, 80, 20); add(text_id); text_id.setBounds(100, 35, 180, 20); add(text_name); text_name.setBounds(100, 60, 180, 20); add(text_tele); text_tele.setBounds(100, 85, 180, 20); /*add(text_level); text_level.setBounds(100,90,180,20);*/ add(text_bal); text_bal.setBounds(100, 135, 180, 20); add(spinner_level); spinner_level.setBounds(100, 110, 180, 20); add(trans_title); trans_title.setBounds(20, 220, 80, 20); add(trans_member); trans_member.setBounds(20, 245, 80, 20); add(trans_money); trans_money.setBounds(20, 270, 80, 20); add(text_member); text_member.setBounds(100, 245, 180, 20); add(text_money); text_money.setBounds(100, 270, 180, 20); add(button_add); button_add.setBounds(100, 165, 100, 25); button_add.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { System.out.println("add"); mm.addMember( text_id.getText(), text_name.getText(), text_tele.getText(), spinner_level.getValue().toString(), text_bal.getText()); member_pane.update_table(); } catch (Exception ex) { JOptionPane.showMessageDialog( mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE); } // dialog_send.setVisible(false); } }); add(button_add_trans); button_add_trans.setBounds(100, 305, 100, 25); button_add_trans.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { System.out.println("add transaction"); Business busi = new Business( text_member.getText(), Float.valueOf(text_money.getText()).floatValue()); busi.addBusi(); busi_pane.update_table(); } catch (Exception ex) { JOptionPane.showMessageDialog( mainFrame, "Adding Failure!", "ERROR", JOptionPane.ERROR_MESSAGE); } // dialog_send.setVisible(false); } }); // set font; member_title.setFont(font_title); member_id.setFont(font); member_name.setFont(font); member_tele.setFont(font); member_level.setFont(font); member_bal.setFont(font); button_add.setFont(font); trans_title.setFont(font_title); trans_member.setFont(font); trans_money.setFont(font); button_add_trans.setFont(font); }
InputFrame() { JPanel pane = new JPanel(); pane.setLayout(null); pane.setBackground(Color.LIGHT_GRAY); add(pane); // JTextField文字欄位元件 lblName = new JLabel("姓名:"); lblName.setBounds(10, 10, 40, 20); pane.add(lblName); text0.setBounds(50, 10, 80, 20); text0.addActionListener(textfield); pane.add(text0); // JSpinner數位序列元件 lblAge = new JLabel("年齡:"); lblAge.setBounds(170, 10, 40, 20); pane.add(lblAge); JSpinner spin = new JSpinner(new SpinnerNumberModel(20, 1, 100, 1)); spin.setBounds(210, 10, 80, 20); spin.addChangeListener(spinner); pane.add(spin); // JRadioButton選項圓鈕元件 lblSex = new JLabel("性別:"); lblSex.setBounds(10, 40, 40, 20); pane.add(lblSex); ButtonGroup group = new ButtonGroup(); JRadioButton rb1 = new JRadioButton("帥哥", false); rb1.setBounds(50, 40, 60, 20); JRadioButton rb2 = new JRadioButton("美女", false); rb2.setBounds(110, 40, 60, 20); rb1.setOpaque(false); rb2.setOpaque(false); // 秀出底色 rb1.addActionListener(radio); rb2.addActionListener(radio); group.add(rb1); group.add(rb2); pane.add(rb1); pane.add(rb2); // JCheckBox核對方塊元件 lblInter = new JLabel("興趣:"); lblInter.setBounds(10, 70, 50, 20); pane.add(lblInter); for (int i = 0; i < check.length; i++) { check[i] = new JCheckBox(checkItem[i]); check[i].setBounds(50 + 60 * i, 70, 60, 20); check[i].setOpaque(false); check[i].addActionListener(checkbox); pane.add(check[i]); } // JComboBox下拉式清單元件 lblAcad = new JLabel("學歷:"); lblAcad.setBounds(10, 100, 50, 20); pane.add(lblAcad); String[] items_c = {"博士", "碩士", "大學", "高中", "國中", "國小"}; JComboBox c_box = new JComboBox(items_c); c_box.setBounds(50, 100, 100, 20); c_box.addItemListener(cbo); pane.add(c_box); // JList清單元件 lblPlace = new JLabel("居住地區:"); lblPlace.setBounds(170, 100, 70, 20); pane.add(lblPlace); String[] items_p = { "台北", "桃園", "新竹", "苗栗", "台中", "彰化", "雲林", "嘉義", "台南", "高雄", "屏東", "花蓮", "台東", "澎湖" }; JList list = new JList(items_p); list.setVisibleRowCount(4); list.addListSelectionListener(list_p); JScrollPane scroll = new JScrollPane(list); scroll.setBounds(240, 100, 80, 80); pane.add(scroll); // JTextArea文字區域元件 texta.setBounds(10, 190, 330, 40); texta.setEditable(false); pane.add(texta); setTitle("輸入元件綜合應用"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(50, 50, 360, 280); setVisible(true); }