Creating Chat Frame in Java Swing.

 Creating Chat Frame in Java Swing.

package javaGuiProject;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class ChatFrameExample {
public static void main(String [] args) {
//Create the Frame
JFrame frame = new JFrame("Hello");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,600);
//Creating the MenuBar and Adding Components
JMenuBar menubar = new JMenuBar();
JMenu menu1 = new JMenu("File");
JMenu menu2 = new JMenu("Help");
menubar.add(menu1);
menubar.add(menu2);
JMenuItem mItem1 = new JMenuItem("Open");
JMenuItem mItem2 = new JMenuItem("Save As");
menu1.add(mItem1);
menu1.add(mItem2);
//Creating the panel as Bottom and adding Components
JPanel panel = new JPanel();//the panel is not visible on output
JLabel label = new JLabel("Enter Text");
JTextField textf = new JTextField(20); // upto 20 Characters
JButton bt1 = new JButton("Send");
JButton bt2 = new JButton("Reset");
panel.add(textf);
panel.add(bt1);
panel.add(bt2);
panel.add(label);//Added Comonents using Flow layout
JTextArea textarea = new JTextArea();
//Adding Components to the Frame
frame.getContentPane().add(BorderLayout.SOUTH,panel);
frame.getContentPane().add(BorderLayout.NORTH,menubar);
frame.getContentPane().add(BorderLayout.CENTER,textf);
frame.setVisible(true);
}

}








Comments

Popular posts from this blog

How to Create JTextField Validation in java swing.

Check Box With Event Listener in java Swing