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); }
private static JPanel initOptionsPane() { JPanel pane = null; ActionAdapter buttonListener = null; // Create an options pane JPanel optionsPane = new JPanel(new GridLayout(4, 1)); // IP address input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Host IP:")); ipField = new JTextField(10); ipField.setText(hostIP); ipField.setEnabled(false); ipField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { ipField.selectAll(); // Should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { hostIP = ipField.getText(); } } }); pane.add(ipField); optionsPane.add(pane); // Port input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Port:")); portField = new JTextField(10); portField.setEditable(true); portField.setText((new Integer(port)).toString()); portField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { // should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { int temp; try { temp = Integer.parseInt(portField.getText()); port = temp; } catch (NumberFormatException nfe) { portField.setText((new Integer(port)).toString()); mainFrame.repaint(); } } } }); pane.add(portField); optionsPane.add(pane); // Host/guest option buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { isHost = e.getActionCommand().equals("host"); // Cannot supply host IP if host option is chosen if (isHost) { ipField.setEnabled(false); ipField.setText("localhost"); hostIP = "localhost"; } else { ipField.setEnabled(true); } } } }; ButtonGroup bg = new ButtonGroup(); hostOption = new JRadioButton("Host", true); hostOption.setMnemonic(KeyEvent.VK_H); hostOption.setActionCommand("host"); hostOption.addActionListener(buttonListener); guestOption = new JRadioButton("Guest", false); guestOption.setMnemonic(KeyEvent.VK_G); guestOption.setActionCommand("guest"); guestOption.addActionListener(buttonListener); bg.add(hostOption); bg.add(guestOption); pane = new JPanel(new GridLayout(1, 2)); pane.add(hostOption); pane.add(guestOption); optionsPane.add(pane); // Connect/disconnect buttons JPanel buttonPane = new JPanel(new GridLayout(1, 2)); buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { // Request a connection initiation if (e.getActionCommand().equals("connect")) { changeStatusNTS(BEGIN_CONNECT, true); } // Disconnect else { changeStatusNTS(DISCONNECTING, true); } } }; connectButton = new JButton("Connect"); connectButton.setMnemonic(KeyEvent.VK_C); connectButton.setActionCommand("connect"); connectButton.addActionListener(buttonListener); connectButton.setEnabled(true); disconnectButton = new JButton("Disconnect"); disconnectButton.setMnemonic(KeyEvent.VK_D); disconnectButton.setActionCommand("disconnect"); disconnectButton.addActionListener(buttonListener); disconnectButton.setEnabled(false); buttonPane.add(connectButton); buttonPane.add(disconnectButton); optionsPane.add(buttonPane); return optionsPane; }
public patientAdd(String s) { super(s); image = new JLabel() { public void paint(Graphics g) { ImageIcon ic = new ImageIcon(str); Image img = ic.getImage(); g.drawImage(img, 0, 0, 150, 150, this); } }; image.setBounds(670, 270, 300, 300); bu = new JButton("UPLOAD"); bu.setBounds(700, 230, 100, 20); bu.addActionListener(this); // q.add(bu); ldt = new JLabel("Date"); lpid = new JLabel("Patient ID"); lpnm = new JLabel("Patient Name"); lgen = new JLabel("Gender"); lbg = new JLabel("Blood Group"); lage = new JLabel("Age"); lwt = new JLabel("Weight Kg"); ladd = new JLabel("Address"); lcno = new JLabel("Cont. no."); ldnm = new JLabel("Doctor Name Dr."); lsym = new JLabel("Symptoms"); ldig = new JLabel("Diagnosis"); lfee = new JLabel("Fee Rs."); cbg = new CheckboxGroup(); cm = new Checkbox("Male", cbg, false); cm.addItemListener(this); cf = new Checkbox("Female", cbg, false); cf.setState(true); cf.addItemListener(this); tdt = new JTextField(15); tpid = new JTextField(6); tpid.addFocusListener(this); tpfnm = new JTextField("first"); tpmnm = new JTextField("middle"); tplnm = new JTextField("last"); tage = new JTextField(4); tage.addFocusListener(this); tbg = new JTextField(6); twt = new JTextField(5); tadd = new TextArea(patient.addr); tcno = new JTextField(20); tdnm = new JTextField(20); tsym = new TextArea(); tdig = new JTextField(20); tfee = new JTextField(6); tfee.addFocusListener(this); ba = new JButton("ADD"); ba.addActionListener(this); bm = new JButton("CANCEL"); bm.addActionListener(this); bd = new JButton("DELETE"); bd.addActionListener(this); bl = new JButton("DISPLAY"); bl.addActionListener(this); bs = new JButton("SEARCH"); bs.addActionListener(this); JPanel p = new JPanel(); p.add(ba); p.add(bm); // p.add(bd); // p.add(bl); // p.add(bs); add(p, BorderLayout.SOUTH); q = new JPanel(); q.setLayout(null); ldt.setBounds(1015, 20, 60, 20); q.add(ldt); tdt.setBounds(1060, 20, 170, 20); q.add(tdt); lpid.setBounds(70, 60, 80, 20); q.add(lpid); tpid.setBounds(200, 60, 60, 20); q.add(tpid); lpnm.setBounds(70, 100, 80, 20); q.add(lpnm); tpfnm.setBounds(200, 100, 100, 20); q.add(tpfnm); tpmnm.setBounds(320, 100, 100, 20); q.add(tpmnm); tplnm.setBounds(440, 100, 100, 20); q.add(tplnm); lgen.setBounds(70, 140, 60, 20); q.add(lgen); lbg.setBounds(370, 140, 80, 20); q.add(lbg); tbg.setBounds(470, 140, 60, 20); q.add(tbg); cm.setBounds(200, 140, 60, 20); cf.setBounds(280, 140, 60, 20); lage.setBounds(70, 180, 40, 20); q.add(lage); tage.setBounds(200, 180, 50, 20); q.add(tage); lwt.setBounds(370, 180, 200, 20); q.add(lwt); twt.setBounds(470, 180, 60, 20); q.add(twt); ladd.setBounds(70, 220, 60, 20); q.add(ladd); tadd.setBounds(200, 220, 350, 50); q.add(tadd); lcno.setBounds(70, 310, 60, 20); q.add(lcno); tcno.setBounds(200, 310, 120, 20); q.add(tcno); ldnm.setBounds(70, 350, 200, 20); q.add(ldnm); tdnm.setBounds(200, 350, 150, 20); q.add(tdnm); lsym.setBounds(70, 390, 100, 20); q.add(lsym); tsym.setBounds(200, 390, 300, 70); q.add(tsym); ldig.setBounds(70, 480, 60, 20); q.add(ldig); tdig.setBounds(200, 480, 100, 20); q.add(tdig); lfee.setBounds(70, 520, 200, 20); q.add(lfee); tfee.setBounds(200, 520, 40, 20); q.add(tfee); q.add(cm); q.add(cf); q.add(image); q.add(bu); add(q, BorderLayout.CENTER); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { patient.con.close(); System.exit(0); } catch (Exception e8) { } } }); System.out.println(tadd.getText()); setSize(1330, 740); setVisible(true); }
DeleteCustomer() { // super(Title, Resizable, Closable, Maximizable, Iconifiable) super("Delete Account Holder", false, true, false, true); setSize(350, 235); jpDel.setLayout(null); lbNo = new JLabel("Account No:"); lbNo.setForeground(Color.black); lbNo.setBounds(15, 20, 80, 25); lbName = new JLabel("Person Name:"); lbName.setForeground(Color.black); lbName.setBounds(15, 55, 90, 25); lbDate = new JLabel("Last Transaction:"); lbDate.setForeground(Color.black); lbDate.setBounds(15, 90, 100, 25); lbBal = new JLabel("Balance:"); lbBal.setForeground(Color.black); lbBal.setBounds(15, 125, 80, 25); txtNo = new JTextField(); txtNo.setHorizontalAlignment(JTextField.RIGHT); txtNo.setBounds(125, 20, 200, 25); txtName = new JTextField(); txtName.setEnabled(false); txtName.setBounds(125, 55, 200, 25); txtDate = new JTextField(); txtDate.setEnabled(false); txtDate.setBounds(125, 90, 200, 25); txtBal = new JTextField(); txtBal.setEnabled(false); txtBal.setHorizontalAlignment(JTextField.RIGHT); txtBal.setBounds(125, 125, 200, 25); // Aligning The Buttons. btnDel = new JButton("Delete"); btnDel.setBounds(20, 165, 120, 25); btnDel.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.setBounds(200, 165, 120, 25); btnCancel.addActionListener(this); // Adding the All the Controls to Panel. jpDel.add(lbNo); jpDel.add(txtNo); jpDel.add(lbName); jpDel.add(txtName); jpDel.add(lbDate); jpDel.add(txtDate); jpDel.add(lbBal); jpDel.add(txtBal); jpDel.add(btnDel); jpDel.add(btnCancel); // Restricting The User Input to only Numerics in Numeric TextBoxes. txtNo.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent ke) { char c = ke.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE)))) { getToolkit().beep(); ke.consume(); } } }); // Checking the Accunt No. Provided By User on Lost Focus of the TextBox. txtNo.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) {} public void focusLost(FocusEvent fe) { if (txtNo.getText().equals("")) { } else { rows = 0; populateArray(); // Load All Existing Records in Memory. findRec(); // Finding if Account No. Already Exist or Not. } } }); // Adding Panel to Window. getContentPane().add(jpDel); populateArray(); // Load All Existing Records in Memory. // In the End Showing the New Account Window. setVisible(true); }