protected void updateTitleForeground() { Color cm = monthTitleComboBox.getForeground(); Color cy = yearTitleComboBox.getForeground(); super.updateTitleForeground(); monthTitleComboBox.setForeground(cm); yearTitleComboBox.setForeground(cy); }
/** Called when something is selected or typed. Goal is to check that everything is valid. */ private boolean checkValid() { if (!this.isShowing()) return true; // prevent to check while init if (!compatibleDimensions()) { jButtonOK.setEnabled(false); for (JComboBox box : image_boxes) { box.setForeground(Color.RED); } jTextAreaInfo.setText(MESSAGES[2]); jTextAreaInfo.setCaretPosition(0); return false; } else { String error = getExpressionError(); if (error.length() != 0) { jButtonOK.setEnabled(false); expressionField.getEditor().getEditorComponent().setForeground(Color.RED); jTextAreaInfo.setText(error); jTextAreaInfo.setCaretPosition(0); return false; } else { jButtonOK.setEnabled(true); for (JComboBox box : image_boxes) { box.setForeground(Color.BLACK); } expressionField.getEditor().getEditorComponent().setForeground(Color.BLACK); jTextAreaInfo.setText(MESSAGES[0]); jTextAreaInfo.setCaretPosition(0); return true; } } }
public static JComboBox getComboBox() { JComboBox component = new JComboBox(); component.setBackground(BACKGROUND_COLOR_TXTA); component.setForeground(TEXT_COLOR); component.setCursor(CURSOR); component.setFont(FONT_TYPE_TXTA); return component; }
@Override public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { // Only the selected component will be edited, so always set the colors to the table's selection // colors. comboBox.setForeground(table.getSelectionForeground()); comboBox.setBackground(table.getSelectionBackground()); for (int i = 0; i < comboBox.getComponentCount(); i++) { if (comboBox.getComponent(i) instanceof AbstractButton) { comboBox.getComponent(i).setBackground(comboBox.getBackground()); } } comboBox.setSelectedItem(value); return comboBox; }
public MirthComboBoxTableCellEditor( JTable table, Object[] items, int clickCount, boolean focusable, final ActionListener actionListener) { this.clickCount = clickCount; comboBox = new JComboBox(items); comboBox.setFocusable(focusable); comboBox.setMaximumRowCount(20); comboBox.setForeground(table.getForeground()); comboBox.setBackground(table.getBackground()); comboBox.setRenderer(new DataTypeListCellRenderer()); // Allow an action listener to be passed in. However, we need to fireEditingStopped after the // action has finished so we wrap it in another listener comboBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (actionListener != null) { actionListener.actionPerformed(e); } fireEditingStopped(); } }); // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4515838 // Workaround to remove the border around the comboBox for (int i = 0; i < comboBox.getComponentCount(); i++) { if (comboBox.getComponent(i) instanceof AbstractButton) { ((AbstractButton) comboBox.getComponent(i)).setBorderPainted(false); } } }
public JPanel Panel() throws IOException { new ImageGet(); Image bgp = ImageGet.getImageByState("arrival"); background = new ImageIcon(bgp); p1.setBounds(0, 0, 942, 821); int b2size = 16; final MTextfield t1 = new MTextfield(); t1.setText(emPO.getPosID()); t1.setOpaque(false); t1.setBorder(BorderFactory.createEmptyBorder()); t1.setEditable(false); final MTextfield t2 = new MTextfield(); t2.setOpaque(false); t2.setBorder(BorderFactory.createEmptyBorder()); Color text = new Color(175, 172, 172); String[] site = {"南京", "上海", "北京", "广州"}; final JComboBox sitebox = new JComboBox(site); sitebox.setBackground(text); sitebox.setForeground(Color.white); String[] state = {"损坏", "完整", "丢失"}; final JComboBox statebox = new JComboBox(state); statebox.setBackground(text); statebox.setForeground(Color.white); String[] columnnames = {"", "", "", "", ""}; Object[][] data = {}; DefaultTableModel model = new DefaultTableModel(data, columnnames); final JTable table = new JTable(model) { public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); if (c instanceof JComponent) { ((JComponent) c).setOpaque(false); } return c; } }; table.setForeground(Color.white); table.setOpaque(false); table.setRowHeight(31); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableColumn yytidColumn = table.getColumnModel().getColumn(0); TableColumn dateColumn = table.getColumnModel().getColumn(1); TableColumn siteColumn = table.getColumnModel().getColumn(2); TableColumn stateColumn = table.getColumnModel().getColumn(3); TableColumn zzzxidColumn = table.getColumnModel().getColumn(4); yytidColumn.setPreferredWidth(87); dateColumn.setPreferredWidth(87); siteColumn.setPreferredWidth(78); stateColumn.setPreferredWidth(80); zzzxidColumn.setPreferredWidth(118); table.getTableHeader().setOpaque(false); JScrollPane jp = new JScrollPane(table); jp.setOpaque(false); jp.getViewport().setOpaque(false); final JTextField time = new JTextField(); Calendar c = Calendar.getInstance(); Date d = c.getTime(); final DatePicker datepick = new DatePicker(time, d); datepick.setOpaque(false); // datepick.setLocale(Locale.CHINA);//设置显示语言 datepick.setPattern("yyyy-MM-dd"); // 设置日期格式化字符串 datepick.setEditorable(false); // 设置是否可编辑 datepick.setPreferredSize(new Dimension(150, 38)); // 设置大小 JButton b4 = new JButton(); b4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String date = datepick.getText(); String place = (String) sitebox.getSelectedItem(); String state = (String) statebox.getSelectedItem(); HallArrivalDocu bussari = new HallArrivalDocu(oos, ois); BussinessArrivalDocuPO badpo = new BussinessArrivalDocuPO(date, t2.getText(), place, state, t1.getText()); // System.out.println(date+" "+t2.getText()+" "+place+" "+state+" // "+t1.getText()); // System.out.println(badpo.getArrivaltime()+badpo.getBussinessID()); boolean isok = bussari.BuildHallArrivalDocu(badpo); System.out.println(isok); Object[] add = {date, t2.getText(), place, state, t1.getText()}; DefaultTableModel model = (DefaultTableModel) table.getModel(); model.insertRow(model.getRowCount(), add); // System.out.println(model.getRowCount()); } }); JButton b5 = new JButton(); b5.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub // ��ȡҪɾ�����,û��ѡ����-1 DefaultTableModel model = (DefaultTableModel) table.getModel(); int row = table.getSelectedRow(); // System.out.println(row); if (row == -1) { Mdialog.showMessageDialog("请选中要删除的行!"); } else { model.removeRow(row); } } }); JButton b6 = new JButton(); b6.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Mdialog.showMessageDialog("成功建立到达单!"); } }); p1.setOpaque(false); p1.setLayout(null); // p1.add(l1); // p1.add(l2); // // p1.add(l3); // p1.add(l4); // p1.add(l5); // p1.add(l6); // p1.add(l7); // p1.add(l8); p1.add(t1); p1.add(t2); p1.add(datepick); p1.add(sitebox); p1.add(statebox); p1.add(b4); p1.add(b5); p1.add(b6); p1.add(jp); b4.setContentAreaFilled(false); b4.setBorder(BorderFactory.createEmptyBorder()); b5.setContentAreaFilled(false); b5.setBorder(BorderFactory.createEmptyBorder()); b6.setContentAreaFilled(false); b6.setBorder(BorderFactory.createEmptyBorder()); int xloc = 184, yloc = 128, length = 150, width = 38, interval = 58; t1.settextFont(); t2.settextFont(); t1.setBounds(xloc, yloc, length, width); datepick.setBounds(xloc, yloc + interval, length, width); sitebox.setBounds(xloc, yloc + interval * 2, length, width); statebox.setBounds(xloc, yloc + interval * 3, length, width); t2.setBounds(xloc, yloc + interval * 4, length, width); jp.setBounds(470, 196, 454, 250); b4.setBounds(96, 455, 280, 82); b5.setBounds(723, 471, 187, 66); b6.setBounds(348, 634, 268, 91); return p1; }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.getContentPane().setBackground(Color.WHITE); frame.getContentPane().setForeground(Color.RED); frame.setBackground(Color.WHITE); frame.setBounds(100, 100, 613, 459); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setForeground(Color.BLACK); tabbedPane.setBackground(Color.WHITE); tabbedPane.setBounds(1, 2, 596, 408); frame.getContentPane().add(tabbedPane); JPanel panel_1 = new JPanel(); panel_1.setBackground(Color.WHITE); panel_1.setForeground(Color.GREEN); tabbedPane.addTab("Recieved Mail", null, panel_1, null); panel_1.setLayout(null); JTextPane textPane_1 = new JTextPane(); textPane_1.setBackground(Color.WHITE); textPane_1.setForeground(Color.BLACK); textPane_1.setEditable(false); JScrollPane scrollPane1 = new JScrollPane(textPane_1); scrollPane1.setBounds(150, 100, 420, 250); panel_1.add(scrollPane1); // panel_1.add(textPane_1); DefaultListModel listModel = new DefaultListModel(); File[] files1 = new File("src/inbox").listFiles(); for (File file : files1) { if (file.isFile()) listModel.addElement((file.getName()).substring(0, (file.getName()).length() - 4)); } JList list = new JList(listModel); list.setForeground(Color.BLACK); list.setBackground(Color.WHITE); // list.setBounds(10, 11, 112, 280); // panel_1.add(list); JScrollPane scrollPane = new JScrollPane(list); // scrollPane.setViewportView(list); scrollPane.setBounds(20, 11, 112, 340); panel_1.add(scrollPane); JLabel lblMessage = new JLabel("Message"); lblMessage.setForeground(Color.BLACK); lblMessage.setBounds(175, 77, 79, 14); panel_1.add(lblMessage); JPanel panel = new JPanel(); panel.setBackground(Color.WHITE); tabbedPane.addTab("Send Email", null, panel, null); panel.setLayout(null); JComboBox contactCombo = new JComboBox(); contactCombo.setForeground(Color.BLACK); contactCombo.setBackground(Color.WHITE); contactCombo.setBounds(172, 21, 409, 20); panel.add(contactCombo); JLabel label = new JLabel("Message:"); label.setForeground(Color.BLACK); label.setBounds(13, 117, 91, 14); panel.add(label); JTextPane messagePane = new JTextPane(); messagePane.setBackground(Color.WHITE); messagePane.setForeground(Color.BLACK); messagePane.setBounds(10, 124, 539, 194); // panel.add(messagePane); JButton button_1 = new JButton("Send"); button_1.setForeground(Color.BLACK); button_1.setBackground(Color.WHITE); button_1.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { String to = contactCombo.getSelectedItem().toString(); String subject = txtSubject.getText(); Random rn = new Random(); String ShareID = Integer.toString((new Random()).nextInt((999999999 - 100) + 1) + 100); System.out.println(ShareID); String from = "src/proxies/proxies.txt"; String message = messagePane.getText(); try { // if(selectedFileIn == true) System.out.println("sendmail1"); SendMail.Distributor(to, ShareID, from, message, "", subject); System.out.println("sendmail2"); // selectedFileIn = false; } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } messagePane.setText(""); contactCombo.repaint(); attField.setText(""); attField.removeAll(); } }); JScrollPane sP = new JScrollPane( messagePane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); sP.setBounds(13, 142, 568, 194); panel.add(sP); button_1.setBounds(482, 346, 99, 23); panel.add(button_1); JLabel lblTo = new JLabel("To"); lblTo.setForeground(Color.BLACK); lblTo.setBackground(Color.BLACK); lblTo.setBounds(116, 24, 46, 14); panel.add(lblTo); attField = new JTextField(); attField.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) {} }); attField.setBounds(172, 52, 409, 20); panel.add(attField); attField.setColumns(10); JButton btnSearchButton = new JButton("Search"); btnSearchButton.setBackground(Color.WHITE); btnSearchButton.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { JFileChooser fileChooser = new JFileChooser(); fileChooser.showOpenDialog(frame); // fileChooser.setCurrentDirectory(new File(System.getProperty("src/"))); selectedFile = fileChooser.getSelectedFile(); attField.setText(selectedFile.getName()); selectedFileIn = true; // selectedFile = fileChooser.getSelectedFile(); } }); btnSearchButton.setBounds(73, 51, 89, 23); panel.add(btnSearchButton); txtSubject = new JTextField(); txtSubject.setBounds(172, 83, 409, 20); panel.add(txtSubject); txtSubject.setColumns(10); JLabel lblSubject = new JLabel("Subject"); lblSubject.setForeground(Color.BLACK); lblSubject.setBackground(Color.BLACK); lblSubject.setBounds(116, 85, 46, 14); panel.add(lblSubject); JPanel panel_2 = new JPanel(); panel_2.setBackground(Color.WHITE); tabbedPane.addTab("Add Contact", null, panel_2, null); panel_2.setLayout(null); JLabel lblEmailAddress = new JLabel("Email Address"); lblEmailAddress.setForeground(Color.BLACK); lblEmailAddress.setBounds(75, 159, 72, 14); panel_2.add(lblEmailAddress); JTextPane proxyPane = new JTextPane(); proxyPane.setForeground(Color.BLACK); proxyPane.setBackground(Color.LIGHT_GRAY); proxyPane.setBounds(157, 159, 298, 102); panel_2.add(proxyPane); JLabel lblContactName = new JLabel("Contact Name"); lblContactName.setForeground(Color.BLACK); lblContactName.setBounds(69, 124, 72, 14); panel_2.add(lblContactName); contactField = new JTextField(); contactField.setBackground(Color.LIGHT_GRAY); contactField.setColumns(10); contactField.setBounds(157, 121, 298, 20); panel_2.add(contactField); JButton btnAddContact = new JButton("Add Contact"); btnAddContact.setBackground(Color.WHITE); btnAddContact.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { BufferedWriter output = null; // Add new contact String conName = contactField.getText(); String allprox = proxyPane.getText(); File conFile = new File("src/contacts/" + conName + ".txt"); try { output = new BufferedWriter(new FileWriter(conFile)); output.write(allprox); output.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnAddContact.setBounds(157, 301, 118, 23); panel_2.add(btnAddContact); // List<String> contacts = new ArrayList<String>(); // comboBox.addItem("hg"); File[] files = new File("src/contacts").listFiles(); for (File file : files) { if (file.isFile()) contactCombo.addItem((file.getName()).substring(0, (file.getName()).length() - 4)); } list.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { String strbldr = ""; String loc = "src/inbox/" + list.getSelectedValue().toString() + ".txt"; try { BufferedReader buffread = new BufferedReader(new FileReader(loc)); String line = buffread.readLine(); while (line != null) { strbldr += line; strbldr += "\n"; line = buffread.readLine(); } buffread.close(); } catch (Exception e) { } ; textPane_1.setText(strbldr); textPane_1.setCaretPosition(0); } }); class Inner extends Thread { public void run() { do { System.out.println("Hello from a thread!"); try { ReceiveMail.run(); scrollPane.repaint(); this.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } while (true); } public void main(String args[]) { (new Inner()).start(); } } Inner reloads = new Inner(); reloads.start(); }
public void createDataEditPanelCourse(String CourseNo, String CourseName, String CourseCredit) { this.CourseNo = CourseNo; this.CourseName = CourseName; this.CourseCredit = CourseCredit; Credit = Float.parseFloat(CourseCredit); if (Credit == 0.75) CreditIndex = 0; else if (Credit == 1.50) CreditIndex = 1; else if (Credit == 3.00) CreditIndex = 2; else CreditIndex = 3; DEPC = new JDialog(); DEPC.setTitle("Course Edit Dialog"); Panel = new JPanel() { protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage( new ImageIcon(getClass().getResource("/Icons/8.jpg")).getImage(), 0, 0, 600, 230, null); ButtonBorder.paintBorder(this, g, 172, 136, 130, 25); } }; Panel.setForeground(Color.WHITE); Panel.setLayout(null); CourseNoLabel1 = new JLabel("Course No. : "); CourseNoLabel1.setForeground(Color.WHITE); CourseNoLabel1.setFont(new Font("Rockwell Extra Bold", Font.PLAIN, 12)); CourseNoLabel1.setBounds(77, 29, 139, 27); Panel.add(CourseNoLabel1); CourseNoLabel2 = new JLabel(this.CourseNo); CourseNoLabel2.setForeground(Color.WHITE); CourseNoLabel2.setFont(new Font("Rockwell Extra Bold", Font.BOLD, 12)); CourseNoLabel2.setBounds(213, 29, 200, 27); Panel.add(CourseNoLabel2); CourseNameLabel = new JLabel("Course Title :"); CourseNameLabel.setForeground(Color.WHITE); CourseNameLabel.setFont(new Font("Rockwell Extra Bold", Font.PLAIN, 12)); CourseNameLabel.setBounds(77, 56, 139, 26); Panel.add(CourseNameLabel); CourseNameField = new JTextField(this.CourseName); CourseNameField.setForeground(Color.WHITE); CourseNameField.setFont(new Font("Rockwell Extra Bold", Font.PLAIN, 10)); CourseNameField.setBounds(213, 60, 200, 20); CourseNameField.setOpaque(false); CourseNameField.setHorizontalAlignment(SwingConstants.CENTER); Panel.add(CourseNameField); CourseCreditLabel = new JLabel("Course Credit :"); CourseCreditLabel.setForeground(Color.WHITE); CourseCreditLabel.setBounds(77, 87, 139, 26); CourseCreditLabel.setFont(new Font("Rockwell Extra Bold", Font.PLAIN, 12)); Panel.add(CourseCreditLabel); CourseCreditBox = new JComboBox<String>(); CourseCreditBox.setBackground(Color.GRAY); CourseCreditBox.setForeground(new Color(28, 0, 0)); CourseCreditBox.setBounds(213, 91, 103, 20); CourseCreditBox.setBorder(ButtonBorder); CourseCreditBox.addItem("0.75"); CourseCreditBox.addItem("1.50"); CourseCreditBox.addItem("3.00"); CourseCreditBox.addItem("4.00"); CourseCreditBox.setMaximumRowCount(3); CourseCreditBox.setSelectedIndex(CreditIndex); Panel.add(CourseCreditBox); UpdateButton = new JButton("Update"); UpdateButton.setForeground(Color.WHITE); UpdateButton.setFont(new Font("Rockwell Extra Bold", Font.BOLD, 10)); UpdateButton.setBounds(173, 137, 128, 23); UpdateButton.setContentAreaFilled(false); UpdateButton.addActionListener(this); Panel.add(UpdateButton); DEPC.getContentPane().add(Panel); DEPC.setSize(500, 230); DEPC.setLocation(500, 200); DEPC.setResizable(false); DEPC.setVisible(true); DEPC.setModal(true); }
Source() { jf = new JFrame("SOURCE::Jamming Simulation"); c = jf.getContentPane(); c.setLayout(null); jf.setSize(1000, 700); // c.setBackground(Color.DARK_GRAY); c.setBackground(new Color(10, 100, 120)); T0.setBounds(450, 30, 350, 45); T0.setFont(f); T0.setForeground(Color.GREEN); T2.setBounds(205, 150, 250, 45); T2.setFont(f2); T2.setForeground(Color.BLUE); T3.setBounds(205, 210, 250, 45); T3.setFont(f2); T3.setForeground(Color.BLUE); T4.setBounds(400, 210, 950, 45); T4.setFont(f2); T4.setForeground(new Color(120, 0, 0)); T5.setBounds(660, 145, 300, 45); T5.setFont(f2); T5.setForeground(Color.CYAN); T6.setBounds(760, 70, 400, 35); T6.setFont(f2); T6.setForeground(Color.RED); T7.setBounds(760, 110, 400, 35); T7.setFont(f2); T7.setForeground(Color.MAGENTA); btn1.setBounds(590, 153, 150, 33); btn1.setFont(f2); // btn1.setBackground(Color.WHITE); btn1.setForeground(new Color(120, 0, 0)); jp.setBounds(105, 126, 719, 450); jp.setBackground(new Color(0, 146, 187)); // jp1.setBackground(new Color(120,0,0)); jp1.setBounds(103, 124, 723, 453); T1.setBounds(300, 550, 250, 45); TAreu.setBounds(650, 550, 200, 35); btn.setBounds(440, 520, 150, 33); T1.setFont(f3); T1.setForeground(new Color(0, 120, 0)); btn.setFont(f2); // btn.setBackground(Color.WHITE); btn.setForeground(new Color(120, 0, 0)); TAreu.addItem("Mesh Route"); TAreu.addItem(" Node "); TAreu.setFont(f3); TAreu.setBackground(Color.WHITE); TAreu.setForeground(Color.BLUE); TAreu.setFont(f); pane.setBounds(385, 280, 400, 200); tf.setColumns(20); tf.setForeground(Color.MAGENTA); tf.setFont(f2); tf.setRows(10); tf.setName("tf"); pane.setName("pane"); pane.setViewportView(tf); ImageIcon ii = new ImageIcon(this.getClass().getResource("Source.jpg")); imageLabel.setIcon(ii); imageLabel.setBounds(0, 2, 1200, 100); btn1.addActionListener(this); btn.addActionListener(this); btn1.setMnemonic(KeyEvent.VK_B); btn.setMnemonic(KeyEvent.VK_S); jf.show(); c.add(btn); c.add(T2); c.add(T3); c.add(T4); c.add(pane, BorderLayout.CENTER); c.add(btn1); // c.add(T0); c.add(imageLabel1); c.add(jp); c.add(jp1); c.add(imageLabel); jf.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent win) { System.exit(0); } }); }
/** Create the frame. */ @SuppressWarnings({"unchecked", "rawtypes"}) public MembersManagement() { connection = DBConnector.dbConnector(); setIconImage( Toolkit.getDefaultToolkit() .getImage( MembersManagement.class.getResource( "/Resources/Custo.Man.Christmas.Folder.Library.ico.png"))); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 1366, 768); contentPane = new JPanel(); contentPane.setBackground(Color.DARK_GRAY); contentPane.setBorder(new LineBorder(Color.BLUE, 1, true)); setContentPane(contentPane); StartPosition.centerOnScreen(this); String[] MemberType = new String[] {"Students", "Teachers"}; JButton button = new JButton("_"); button.setBounds(1234, 1, 44, 23); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { MinFrame(); } }); contentPane.setLayout(null); button.setForeground(Color.WHITE); button.setFocusable(false); button.setBackground(Color.DARK_GRAY); contentPane.add(button); JButton button_1 = new JButton(""); button_1.setBounds(1277, 1, 44, 23); button_1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { MaxFrame(); } }); button_1.setIcon(new ImageIcon(MembersManagement.class.getResource("/Resources/Maximize.png"))); button_1.setForeground(Color.WHITE); button_1.setFocusable(false); button_1.setBackground(Color.DARK_GRAY); contentPane.add(button_1); JButton button_2 = new JButton("X"); button_2.setBounds(1321, 1, 44, 23); button_2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { CloseFrame(); } }); button_2.setForeground(Color.WHITE); button_2.setFont(new Font("Ubuntu", Font.BOLD, 8)); button_2.setFocusable(false); button_2.setBackground(Color.RED); contentPane.add(button_2); Border emptyBorder = BorderFactory.createEmptyBorder(); JLabel lblStudentsManagement = new JLabel("Members Management"); lblStudentsManagement.setBounds(403, 34, 543, 78); lblStudentsManagement.setHorizontalAlignment(SwingConstants.CENTER); lblStudentsManagement.setForeground(new Color(255, 255, 255)); lblStudentsManagement.setFont(new Font("Ubuntu", Font.BOLD, 36)); contentPane.add(lblStudentsManagement); String[] searchCriteria = new String[] {"Name", "Registration Number"}; JPanel panel3 = new JPanel(); panel3.setBackground(Color.DARK_GRAY); panel3.setBorder(new LineBorder(Color.BLUE)); panel3.setBounds(14, 187, 1340, 568); contentPane.add(panel3); panel3.setLayout(null); panel3.setVisible(false); JLabel lblSelectSearchCriteria = new JLabel("Select Search Criteria"); lblSelectSearchCriteria.setForeground(Color.WHITE); lblSelectSearchCriteria.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblSelectSearchCriteria.setBounds(487, 39, 149, 21); panel3.add(lblSelectSearchCriteria); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(10, 99, 1320, 402); panel3.add(scrollPane_1); table_1 = new JTable(); table_1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); table_1.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); scrollPane_1.setViewportView(table_1); JLabel lblCriteria = new JLabel("Name"); lblCriteria.setForeground(Color.WHITE); lblCriteria.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblCriteria.setBounds(952, 39, 149, 21); panel3.add(lblCriteria); JComboBox cmbSearchCriteria = new JComboBox(searchCriteria); cmbSearchCriteria.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (cmbSearchCriteria.getSelectedItem().toString() == "Name") { lblCriteria.setText("Name"); txtSearch.setBounds(1001, 37, 160, 25); } else if (cmbSearchCriteria.getSelectedItem().toString() == "Registration Number") { lblCriteria.setText("Registration Number"); txtSearch.setBounds(1100, 37, 160, 25); } } }); cmbSearchCriteria.setForeground(Color.WHITE); cmbSearchCriteria.setFont(new Font("Ubuntu", Font.PLAIN, 13)); cmbSearchCriteria.setBorder(emptyBorder); cmbSearchCriteria.setBackground(Color.DARK_GRAY); cmbSearchCriteria.setBounds(646, 39, 160, 20); panel3.add(cmbSearchCriteria); JComboBox cmbType = new JComboBox(MemberType); cmbType.setForeground(Color.WHITE); cmbType.setFont(new Font("Ubuntu", Font.PLAIN, 13)); cmbType.setBackground(Color.DARK_GRAY); cmbType.setBounds(246, 39, 160, 20); panel3.add(cmbType); JLabel lblSearchBy = new JLabel("Search By"); lblSearchBy.setForeground(Color.WHITE); lblSearchBy.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblSearchBy.setBounds(885, 39, 75, 21); panel3.add(lblSearchBy); txtSearch = new JTextField(); txtSearch.addKeyListener( new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String type = cmbType.getSelectedItem().toString(); String sCriteria = cmbSearchCriteria.getSelectedItem().toString(); if (type == "Students") { if (sCriteria == "Name") { try { LibMemberDM bDM = new LibMemberDM(); table_1.setModel( DbUtils.resultSetToTableModel(bDM.searchByNameS(txtSearch.getText()))); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } else if (sCriteria == "Registration Number") { try { LibMemberDM bDM = new LibMemberDM(); table_1.setModel( DbUtils.resultSetToTableModel(bDM.searchByRegNoS(txtSearch.getText()))); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } } else if (type == "Teachers") { if (sCriteria == "Name") { try { LibMemberDM bDM = new LibMemberDM(); table_1.setModel( DbUtils.resultSetToTableModel(bDM.searchByNameT(txtSearch.getText()))); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } else if (sCriteria == "Registration Number") { try { LibMemberDM bDM = new LibMemberDM(); table_1.setModel( DbUtils.resultSetToTableModel(bDM.searchByRegNoT(txtSearch.getText()))); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } } } }); txtSearch.setForeground(Color.WHITE); txtSearch.setFont(new Font("Ubuntu", Font.PLAIN, 13)); txtSearch.setBorder(emptyBorder); txtSearch.setBackground(Color.GRAY); txtSearch.setBounds(1001, 37, 200, 25); panel3.add(txtSearch); txtSearch.setColumns(10); JButton btnUpdate = new JButton("Update"); btnUpdate.setFont(new Font("Ubuntu", Font.PLAIN, 12)); btnUpdate.setBackground(Color.DARK_GRAY); btnUpdate.setForeground(Color.WHITE); btnUpdate.setBounds(518, 523, 89, 23); panel3.add(btnUpdate); JButton btnRemove = new JButton("Remove"); btnRemove.setFont(new Font("Ubuntu", Font.PLAIN, 12)); btnRemove.setBackground(Color.DARK_GRAY); btnRemove.setForeground(Color.WHITE); btnRemove.setBounds(676, 523, 89, 23); panel3.add(btnRemove); JLabel lblSelectMemberType = new JLabel("Select Member Type"); lblSelectMemberType.setForeground(Color.WHITE); lblSelectMemberType.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblSelectMemberType.setBounds(97, 39, 149, 21); panel3.add(lblSelectMemberType); JPanel panel1 = new JPanel(); panel1.setBorder(new LineBorder(Color.BLUE)); panel1.setBackground(Color.DARK_GRAY); panel1.setBounds(14, 187, 1340, 568); contentPane.add(panel1); panel1.setVisible(true); panel1.setLayout(null); JComboBox cmbMemType = new JComboBox(MemberType); cmbMemType.setForeground(Color.WHITE); cmbMemType.setFont(new Font("Ubuntu", Font.PLAIN, 13)); cmbMemType.setBorder(emptyBorder); cmbMemType.setBackground(Color.DARK_GRAY); cmbMemType.setBounds(449, 39, 146, 25); panel1.add(cmbMemType); JButton btnView = new JButton("View Members"); btnView.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { String Type = cmbMemType.getSelectedItem().toString(); try { if (Type == "Students") { String Query = "select t2.MemID, t1.FullName, t1.Address, t1.DOB, t1.NIC, t1.Sex, t1.ContactNo, t1.CurrentGrade, t1.CurrentClass from StudentsMF t1, LibMem t2 where t1.RegNo = t2.RegNoS"; PreparedStatement pst = connection.prepareStatement(Query); ResultSet rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); rs.close(); pst.close(); } else if (Type == "Teachers") { String Query = "select t2.MemID, t1.Name, t1.Adress, t1.DOB, t1.NIC, t1.Sex, t1.ContactNo, t1.TGrade, t1.Type from TeachersMF t1, LibMem t2 where t1.RegNo = t2.RegNoT"; PreparedStatement pst = connection.prepareStatement(Query); ResultSet rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); rs.close(); pst.close(); } } catch (Exception e) { e.printStackTrace(); } } }); btnView.setForeground(Color.WHITE); btnView.setBackground(Color.DARK_GRAY); btnView.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnView.setBounds(736, 36, 131, 30); panel1.add(btnView); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(10, 99, 1320, 458); panel1.add(scrollPane); table = new JTable(); table.setGridColor(Color.GRAY); table.setFont(new Font("Ubuntu", Font.PLAIN, 11)); table.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); table.setBackground(Color.WHITE); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); scrollPane.setViewportView(table); JPanel panel2 = new JPanel(); panel2.setBorder(new LineBorder(Color.BLUE)); panel2.setBackground(Color.DARK_GRAY); panel2.setBounds(14, 187, 1340, 568); contentPane.add(panel2); panel2.setLayout(null); JLabel lblISBN = new JLabel("Registration Number"); lblISBN.setForeground(Color.WHITE); lblISBN.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblISBN.setBounds(232, 183, 142, 22); panel2.add(lblISBN); txtRegNo = new JTextField(); txtRegNo.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); txtRegNo.setBackground(Color.GRAY); txtRegNo.setForeground(Color.WHITE); txtRegNo.setFont(new Font("Ubuntu", Font.PLAIN, 13)); txtRegNo.setBounds(413, 182, 208, 24); txtRegNo.setBorder(emptyBorder); panel2.add(txtRegNo); txtRegNo.setColumns(10); txtPassword = new JTextField(); txtPassword.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); txtPassword.setForeground(Color.WHITE); txtPassword.setFont(new Font("Ubuntu", Font.PLAIN, 13)); txtPassword.setBorder(emptyBorder); txtPassword.setColumns(10); txtPassword.setBackground(Color.GRAY); txtPassword.setBounds(413, 214, 208, 24); panel2.add(txtPassword); JLabel lblName = new JLabel("Password"); lblName.setForeground(Color.WHITE); lblName.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblName.setBounds(232, 215, 142, 22); panel2.add(lblName); JLabel lblNicNumber = new JLabel("Re-Enter Password"); lblNicNumber.setForeground(Color.WHITE); lblNicNumber.setFont(new Font("Ubuntu", Font.PLAIN, 13)); lblNicNumber.setBounds(232, 248, 142, 22); panel2.add(lblNicNumber); txtRPassword = new JTextField(); txtRPassword.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); txtRPassword.setForeground(Color.WHITE); txtRPassword.setFont(new Font("Ubuntu", Font.PLAIN, 13)); txtRPassword.setBorder(emptyBorder); txtRPassword.setColumns(10); txtRPassword.setBackground(Color.GRAY); txtRPassword.setBounds(413, 247, 208, 24); panel2.add(txtRPassword); JButton btnClear = new JButton("Clear"); btnClear.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { clearFeilds(); } }); btnClear.setForeground(Color.WHITE); btnClear.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnClear.setBackground(Color.DARK_GRAY); btnClear.setBounds(474, 344, 110, 32); panel2.add(btnClear); JButton btnAddMember = new JButton("Add Member"); btnAddMember.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!txtRPassword.getText().equals("") || !txtPassword.getText().equals("") || !txtRegNo.getText().equals("")) { if (txtPassword.getText().equals(txtRPassword.getText())) { try { LibMemberDM mDM = new LibMemberDM(); LibMember member = new LibMember(); member.setMemID(txtRegNo.getText()); member.setPassword(txtPassword.getText()); // checking whether RegNo exist in the database { String query1 = "select RegNo from TeachersMF where RegNo=?"; String query2 = "select RegNo from StudentsMF where RegNo=?"; PreparedStatement pst1 = connection.prepareStatement(query1); pst1.setString(1, member.getMemID()); PreparedStatement pst2 = connection.prepareStatement(query2); pst2.setString(1, member.getMemID()); ResultSet rs1 = pst1.executeQuery(); ResultSet rs2 = pst2.executeQuery(); int count1 = 0, count2 = 0; while (rs1.next()) count1++; while (rs2.next()) count2++; if (count1 == 0 && count2 == 0) JOptionPane.showMessageDialog( null, "Registration Number does not exist!", "Error", JOptionPane.WARNING_MESSAGE); else if (count1 == 1 && count2 == 0) { String query3 = "select MemID from LibMem where MemID='" + member.getMemID() + "'"; PreparedStatement pst3 = connection.prepareStatement(query3); ResultSet rs3 = pst3.executeQuery(); int count3 = 0; while (rs3.next()) count3++; if (count3 != 0) JOptionPane.showMessageDialog(null, "User Already Exist!"); else if (count3 == 0) { if (mDM.insertMemberT(member)) { JOptionPane.showMessageDialog(null, "Successful"); clearFeilds(); } else JOptionPane.showMessageDialog(null, "Failed"); rs3.close(); pst3.close(); } } else if (count1 == 0 && count2 == 1) { String query6 = "select * from LibMem where MemID='" + member.getMemID() + "'"; PreparedStatement pst5 = connection.prepareStatement(query6); ResultSet rs4 = pst5.executeQuery(); int count3 = 0; while (rs4.next()) count3++; if (count3 != 0) JOptionPane.showMessageDialog(null, "User Already Exist!"); else if (count3 == 0) { if (mDM.insertMemberS(member)) { JOptionPane.showMessageDialog(null, "Successful"); clearFeilds(); } else JOptionPane.showMessageDialog(null, "Failed"); rs4.close(); pst5.close(); } } rs1.close(); rs2.close(); pst1.close(); pst2.close(); } catch (Exception x) { JOptionPane.showMessageDialog(null, x); System.out.println(x); } } else JOptionPane.showMessageDialog(null, "Passwords do not Match"); } else JOptionPane.showMessageDialog(null, "Fill in All the Details"); } }); btnAddMember.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnAddMember.setBackground(Color.DARK_GRAY); btnAddMember.setForeground(Color.WHITE); btnAddMember.setBounds(265, 344, 125, 32); panel2.add(btnAddMember); JLabel label = new JLabel(""); label.setIcon( new ImageIcon(MembersManagement.class.getResource("/Resources/sign-up-icon.png"))); label.setBounds(856, 140, 256, 226); panel2.add(label); panel2.setVisible(false); // Creating Tab Buttons of Tabs Pane JButton btnEditStudentDetails = new JButton("Edit Member Details"); JButton btnAddStudents = new JButton("Add Members"); JButton btnViewStudents = new JButton("View Members"); btnViewStudents.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnViewStudents.setForeground(Color.WHITE); btnViewStudents.setBackground(Color.BLUE); btnViewStudents.setBounds(14, 164, 124, 23); contentPane.add(btnViewStudents); btnAddStudents.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (btnAddStudents.hasFocus()) { btnAddStudents.setBackground(Color.BLUE); btnAddStudents.setForeground(Color.WHITE); btnViewStudents.setBackground(Color.DARK_GRAY); btnViewStudents.setForeground(Color.WHITE); btnEditStudentDetails.setBackground(Color.DARK_GRAY); btnEditStudentDetails.setForeground(Color.WHITE); } if (panel2.isVisible() == false) { panel2.setVisible(true); panel1.setVisible(false); panel3.setVisible(false); } } }); btnAddStudents.setForeground(Color.WHITE); btnAddStudents.setBorder(BorderFactory.createLineBorder(Color.BLUE)); btnAddStudents.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnAddStudents.setBackground(Color.DARK_GRAY); btnAddStudents.setBounds(137, 164, 144, 23); contentPane.add(btnAddStudents); btnEditStudentDetails.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (btnEditStudentDetails.hasFocus()) { btnEditStudentDetails.setBackground(Color.BLUE); btnEditStudentDetails.setForeground(Color.WHITE); btnAddStudents.setBackground(Color.DARK_GRAY); btnAddStudents.setForeground(Color.WHITE); btnViewStudents.setBackground(Color.DARK_GRAY); btnViewStudents.setForeground(Color.WHITE); } if (panel3.isVisible() == false) { panel3.setVisible(true); panel1.setVisible(false); panel2.setVisible(false); } } }); btnEditStudentDetails.setForeground(Color.WHITE); btnEditStudentDetails.setBorder(BorderFactory.createLineBorder(Color.BLUE)); btnEditStudentDetails.setFont(new Font("Ubuntu", Font.PLAIN, 13)); btnEditStudentDetails.setBackground(Color.DARK_GRAY); btnEditStudentDetails.setBounds(280, 164, 169, 23); contentPane.add(btnEditStudentDetails); btnViewStudents.setBorder(BorderFactory.createLineBorder(Color.BLUE)); btnViewStudents.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (btnViewStudents.hasFocus()) { btnViewStudents.setBackground(Color.BLUE); btnViewStudents.setForeground(Color.WHITE); btnAddStudents.setBackground(Color.DARK_GRAY); btnAddStudents.setForeground(Color.WHITE); btnEditStudentDetails.setBackground(Color.DARK_GRAY); btnEditStudentDetails.setForeground(Color.WHITE); } if (panel1.isVisible() == false) { panel1.setVisible(true); panel2.setVisible(false); panel3.setVisible(false); } } }); }
private void initImportItemField() { // TODO Auto-generated method stub XLabel dataLabel = new XLabel("开始时间:"); dataField = new JTextField(); dataLabel.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); dataField.setPreferredSize(new Dimension(100, 26)); ser = XTimeChooser.getInstance(); ser.register(dataField); start = ser.getTimePO(); dataField.setText(ser.getCurrentTime()); dataField.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); box1 = new JComboBox(); box2 = new JComboBox(); box1.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); box2.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); for (int i = 0; i <= 23; i++) { box1.addItem(i + "时"); box2.addItem(i + "时"); } XLabel dataLabel2 = new XLabel("结束时间:"); dataField2 = new JTextField(); dataLabel2.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); dataField2.setPreferredSize(new Dimension(100, 26)); ser2 = XTimeChooser.getInstance(); ser2.register(dataField2); end = ser2.getTimePO(); dataField2.setText(ser2.getCurrentTime()); dataField2.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); InNums = new XLabel("入库数量:"); Inshow = new JLabel(); InNums.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); Inshow.setPreferredSize(new Dimension(50, 26)); numlabel = new XLabel("仓库数量:"); numshow = new JLabel(); numlabel.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); numshow.setPreferredSize(new Dimension(50, 26)); OutNums = new XLabel("出库数量:"); Outshow = new JLabel(); OutNums.setForeground(XContorlUtil.DEFAULT_PAGE_TEXT_COLOR); Outshow.setPreferredSize(new Dimension(50, 26)); XButton addItemButton = new XButton("提交"); addItemButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { submit(); LogBLService.insert( TimePO.getNowTimePO(), bl.getPo().getPermission().toString() + bl.getPo().getUsername() + "查看了库存"); } catch (ClassNotFoundException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); JPanel inputPanel = new JPanel(); // inputPanel.setBackground(XContorlUtil.MENUITEM_BACKGROUND); inputPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); inputPanel.add(dataLabel); inputPanel.add(dataField); inputPanel.add(box1); inputPanel.add(dataLabel2); inputPanel.add(dataField2); inputPanel.add(box2); inputPanel.add(addItemButton); add(inputPanel, BorderLayout.NORTH); inputPanel.add(InNums); inputPanel.add(Inshow); inputPanel.add(OutNums); inputPanel.add(Outshow); inputPanel.add(numlabel); inputPanel.add(numshow); }