Berikut tampilannya:
codingnya sebagai berikut :
import java.awt.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
public class ChatClient{
Frame fr;
Panel pane;
TextField tf;
TextArea ta;
Button btnSend;
Button btnQuit;
Choice ch;
JMenu menuF, menuH;
JMenuBar menuBar;
JMenuItem menuItem1, menuItem2;
public void launchFrame(){
fr = new Frame("Chat Client");
fr.setSize(650,200);
fr.setVisible(true);
fr.setBackground(Color.yellow);
pane = new Panel();
pane.setSize(50,50);
//pane.setBackground(Color.yellow);
pane.setVisible(true);
tf = new TextField("");
//tf.setSize(50,100);
tf.setVisible(true);
btnSend = new Button("Send");
btnQuit = new Button("Quit");
menuBar = new JMenuBar();
menuF = new JMenu("File");
menuF.setMnemonic(KeyEvent.VK_F);
//menu.getAccessibleContext().setAccessibleDescription(
// "Hanya menu ini yang memiliki item menu");
menuBar.add(menuF);
menuItem1 = new JMenuItem("Quit");
menuItem1.setMnemonic(KeyEvent.VK_X);
menuItem1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
System.exit(0);
}
});
menuF.add(menuItem1);
menuH = new JMenu("Help");
menuH.setMnemonic(KeyEvent.VK_H);
menuBar.add(menuH);
menuItem2 = new JMenuItem("About");
menuH.add(menuItem2);
ch = new Choice();
ch.addItem("--Pilih--");
ch.add("Richer :");
ch.add("Enny :");
ch.add("Eldear :");
ta = new TextArea("");
ta.getMinimumSize(400,150);
ta.setVisible(true);
ta.setEditable(false);
ta.setBackground(Color.green);
fr.add(pane, BorderLayout.EAST);
fr.add(tf, BorderLayout.PAGE_END);
fr.add(ta, BorderLayout.LINE_START);
fr.add(menuBar, BorderLayout.NORTH);
pane.add(btnSend, BorderLayout.LINE_START);
pane.add(btnQuit, BorderLayout.LINE_END);
pane.add(ch, BorderLayout.PAGE_START);
btnQuit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
System.exit(0);
}
});
btnSend.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Toolkit.getDefaultToolkit().beep();
String IsiText = tf.getText();
String User = ch.getSelectedItem();
ta.append(User +" ");
ta.append(IsiText);
ta.append("\n");
tf.setText("");
}
});
/* ch.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
String User = ch.getSelectedItem();
}
});
*/
tf.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_ENTER){
Toolkit.getDefaultToolkit().beep();
String IsiText = tf.getText();
String User = ch.getSelectedItem();
ta.append(User +" ");
ta.append(IsiText);
ta.append("\n");
tf.setText("");
}
}
});
fr.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Toolkit.getDefaultToolkit().beep();
System.exit(0);
}
});
fr.pack();
}
public static void main(String args[]){
ChatClient tampilan = new ChatClient();
tampilan.launchFrame();
}
}
selamat mencoba semoga sukses??????????
3 comments
hi cinta?
Reply(ngajak chat) :p
iya sayng?????
Replyserver nya gan???
ReplyPost a Comment