import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ChatClient extends JFrame{
JTextArea output;
JTextField input;
public ChatClient(){
//initialize
setTitle("Chat & Bot");
getContentPane().setLayout(new BorderLayout(5,5)); //(5,5)Abstand zwischen den Elementen
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 400);
//output-field
output = new JTextArea();
output.setEditable(true);
output.setLineWrap(true); //automatischer Zeilenumbruch
output.setWrapStyleWord(true); //Bei Zeilenumbruch Wort nicht trennen
JScrollPane scrollerOutput = new JScrollPane();
scrollerOutput.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollerOutput.getViewport().setView(output);
scrollerOutput.setPreferredSize(new Dimension(450,350));
getContentPane().add(scrollerOutput, BorderLayout.CENTER);
//UserList
String[] user = {"Test", "Test2", "Test3"};
JList userlist = new JList(user);
JScrollPane scrollerUserList = new JScrollPane();
scrollerUserList.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollerUserList.getViewport().setView(userlist);
getContentPane().add(scrollerUserList, BorderLayout.EAST);
//SplitPane
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setRightComponent(scrollerUserList);
splitPane.setLeftComponent(scrollerOutput);
splitPane.setOneTouchExpandable(true);
splitPane.setContinuousLayout(true);
getContentPane().add(splitPane, BorderLayout.CENTER);
//panel1
JPanel panel1 = new JPanel();
panel1.setLayout(new BorderLayout(5,5));
getContentPane().add(panel1, BorderLayout.SOUTH);
//send-button
JButton send = new JButton("Send");
panel1.add(send, BorderLayout.EAST);
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//send Message
}
});
//input-field
input = new JTextField();
panel1.add(input, BorderLayout.CENTER);
//MenuBar
JMenuBar menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
//File
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
fileMenu.add(new AbstractAction("Close") {
public void actionPerformed(ActionEvent e) {
close();
}
});
//Help
JMenu helpMenu = new JMenu("?");
menuBar.add(helpMenu);
helpMenu.add(new AbstractAction("Help") {
public void actionPerformed(ActionEvent e) {
//Action Help
}
});
} //end c-tor
//Close-Window
public void close (){
System.exit(0);
}
public static void main(String[] args) {
ChatClient client = new ChatClient();
client.setVisible(true);
}
}