private void initUI() { // Create tabbed pane with commands in it tabbedPane = new JTabbedPane(); getContentPane().add(tabbedPane, BorderLayout.NORTH); tabbedPane.addTab("Book", null, createBookPane(), "View book information"); tabbedPane.addTab("Author", null, createAuthorPane(), "View author information"); tabbedPane.addTab("Customer", null, createCustomerPane(), "View customer information"); tabbedPane.addTab("Borrow Book", null, createBorrowPane(), "Borrow books for a customer"); tabbedPane.addTab("Return Book", null, createReturnPane(), "Return books for a customer"); // Create output area with scrollpane outputArea = new JTextArea(); // outputArea.setFont(new Font("Monospaced",Font.PLAIN,12)); outputArea.setFont(new Font("Monospaced", Font.ROMAN_BASELINE, 12)); outputArea.setEditable(false); outputArea.setFocusable(false); outputArea.setTabSize(2); JScrollPane sp = new JScrollPane(outputArea); sp.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS); getContentPane().add(sp, BorderLayout.CENTER); // Create menus JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); JMenuItem clearTextMenuItem = new JMenuItem(clearTextAction); JMenuItem exitMenuItem = new JMenuItem(exitAction); fileMenu.add(clearTextMenuItem); fileMenu.addSeparator(); fileMenu.add(exitMenuItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); // Pack it all pack(); }
public EchoAWT() throws UnknownHostException { super("채팅 프로그램"); // 각종 정의 h = new JPanel(new GridLayout(2, 3)); m = new JPanel(new BorderLayout()); f = new JPanel(new BorderLayout()); s = new JPanel(new BorderLayout()); login = new JPanel(new BorderLayout()); // name = new JLabel(" 사용자 이름 "); name = new JLabel(" 메세지 입력 "); jta = new JTextArea(); // clientList = new JTextArea(0, 10); clientList = new JList(); jsp = new JScrollPane(jta); list = new JScrollPane(clientList); jtf = new JTextField("입력하세요."); hi = new JTextField("HOST IP 입력"); pi = new JTextField("PORT 입력"); localport = new JTextField("원하는 PORT 입력"); lid = new JTextField("ID를 입력하세요."); lpw = new JTextField("PW를 입력하세요."); serveropen = new JButton("서버 오픈"); textin = new JButton("입력"); clientin = new JButton("서버 접속"); conf = new JButton("로그인"); join = new JButton("회원가입"); addr = InetAddress.getLocalHost(); // 사용자 해상도 및 창 크기 설정 및 가져오기. Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); setSize(500, 500); Dimension d = getSize(); // 각종 버튼 및 텍스트 필드 리스너 jtf.addActionListener(this); hi.addActionListener(this); pi.addActionListener(this); localport.addActionListener(this); lid.addActionListener(this); lpw.addActionListener(this); conf.addActionListener(this); join.addActionListener(this); serveropen.addActionListener(this); clientin.addActionListener(this); textin.addActionListener(this); jtf.addFocusListener(this); hi.addFocusListener(this); pi.addFocusListener(this); localport.addFocusListener(this); lid.addFocusListener(this); lpw.addFocusListener(this); // 서버 접속 h.add(hi); h.add(pi); h.add(clientin); // 서버 생성 h.add(new JLabel("IP : " + addr.getHostAddress(), (int) CENTER_ALIGNMENT)); h.add(localport); h.add(serveropen); // 채팅글창 글 작성 막기 jta.setEditable(false); // 접속자 리스트 width 제한 clientList.setFixedCellWidth(d.width / 3); // 입력 창 f.add(name, "West"); f.add(jtf, "Center"); f.add(textin, "East"); // 접속자 확인창 s.add(new JLabel("접속자", (int) CENTER_ALIGNMENT), "North"); s.add(list, "Center"); // clientList.setEditable(false); // 메인 창 m.add(jsp, "Center"); m.add(s, "East"); // 프레임 설정 add(h, "North"); add(m, "Center"); add(f, "South"); // 로그인 다이얼로그 jd = new JDialog(); jd.setTitle("채팅 로그인"); jd.add(login); jd.setSize(200, 200); Dimension dd = jd.getSize(); jd.setLocation(screenSize.width / 2 - (dd.width / 2), screenSize.height / 2 - (dd.height / 2)); jd.setVisible(true); // 로그인창 JPanel lm = new JPanel(new GridLayout(4, 1)); lm.add(lid); lm.add(new Label()); lm.add(lpw); lm.add(new Label()); JPanel bt = new JPanel(); bt.add(conf); bt.add(join); login.add(new Label(), "North"); login.add(new Label(), "West"); login.add(new Label(), "East"); login.add(lm, "Center"); login.add(bt, "South"); // 창의 위치, 보임, EXIT 단추 활성화. setLocation(screenSize.width / 2 - (d.width / 2), screenSize.height / 2 - (d.height / 2)); setVisible(false); setDefaultCloseOperation(EXIT_ON_CLOSE); }
public QueryDBFrame() { setTitle("QueryDB"); setSize(400, 300); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); authors = new JComboBox(); authors.setEditable(false); authors.addItem("Any"); publishers = new JComboBox(); publishers.setEditable(false); publishers.addItem("Any"); result = new JTextArea(4, 50); result.setEditable(false); priceChange = new JTextField(8); priceChange.setText("-5.00"); try { // 连接数据库 con = getConnection(); stmt = con.createStatement(); // 将数据库中的作者名添加到组合框 String query = "SELECT Name FROM Authors"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) authors.addItem(rs.getString(1)); // 将出版社名添加到组合框 query = "SELECT Name FROM Publishers"; rs = stmt.executeQuery(query); while (rs.next()) publishers.addItem(rs.getString(1)); } catch (Exception e) { result.setText("Error " + e); } gbc.fill = GridBagConstraints.NONE; gbc.weightx = 100; gbc.weighty = 100; add(authors, gbc, 0, 0, 2, 1); add(publishers, gbc, 2, 0, 2, 1); gbc.fill = GridBagConstraints.NONE; JButton queryButton = new JButton("Query"); queryButton.addActionListener(this); add(queryButton, gbc, 0, 1, 1, 1); JButton changeButton = new JButton("Change prices"); changeButton.addActionListener(this); add(changeButton, gbc, 2, 1, 1, 1); gbc.fill = GridBagConstraints.HORIZONTAL; add(priceChange, gbc, 3, 1, 1, 1); gbc.fill = GridBagConstraints.BOTH; add(result, gbc, 0, 2, 4, 1); }
public void createGUI() { setLayout(new BorderLayout()); JPanel topPan = new JPanel(new BorderLayout()); // topPan.setBorder(BorderFactory.createRaisedSoftBevelBorder()); JPanel topCentPan = new JPanel(); JLabel titleLab = new JLabel(); titleLab.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 15)); topCentPan.add(titleLab); JPanel topRightPan = new JPanel(); // Cursor handCursor = new Cursor(Cursor.HAND_CURSOR); replyBut = new JButton(new ImageIcon("src\\images\\replyIcon.png")); replyBut.setBorder(BorderFactory.createEmptyBorder()); replyBut.addActionListener(this); replyBut.setCursor(new Cursor(Cursor.HAND_CURSOR)); replyBut.setToolTipText("Reply"); replyBut.setContentAreaFilled(false); replyBut.setRolloverEnabled(true); forwardBut = new JButton(new ImageIcon("src\\images\\forwardIcon.png")); forwardBut.setBorder(BorderFactory.createEmptyBorder()); forwardBut.addActionListener(this); forwardBut.setCursor(new Cursor(Cursor.HAND_CURSOR)); forwardBut.setToolTipText("Forward"); forwardBut.setContentAreaFilled(false); forwardBut.setRolloverEnabled(true); topRightPan.add(replyBut); topRightPan.add(forwardBut); topPan.add(topCentPan, "Center"); topPan.add(topRightPan, "East"); JPanel centPan = new JPanel(new BorderLayout()); JPanel centTopPan = new JPanel(new BorderLayout()); JPanel centTopLeftPan = new JPanel(); JLabel fromLab = new JLabel(); fromLab.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); JTextArea contentTA = new JTextArea(); // JEditorPane contentTA = new JEditorPane(JEditorPane.W3C_LENGTH_UNITS,""); contentTA.setLineWrap(true); contentTA.setEditable(false); centTopLeftPan.add(fromLab); JPanel centTopRightPan = new JPanel(); JLabel dateLab = new JLabel(); dateLab.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); centTopRightPan.add(dateLab); centTopPan.add(centTopLeftPan, "West"); centTopPan.add(centTopRightPan, "East"); centPan.add(centTopPan, "North"); centPan.add(new JScrollPane(contentTA), "Center"); add(topPan, "North"); add(centPan, "Center"); try { workingSet.absolute(pointer + 1); msgID = Home.bodyPan.msgID[pointer]; titleLab.setText(workingSet.getString("subject")); fromLab.setText("From: " + workingSet.getString("mail_addresses")); dateLab.setText(workingSet.getString("sent_date")); contentTA.setText(workingSet.getString("content")); } catch (SQLException sqlExc) { JOptionPane.showMessageDialog(this, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE); } Home.bodyPan.remove(Home.bodyPan.contentPan); Home.bodyPan.contentPan = new JScrollPane(this); Home.bodyPan.add(Home.bodyPan.contentPan); Home.home.homeFrame.setVisible(true); }