Day 3:qqmain.java

Source: Internet
Author: User

Import java.awt.*;
Import javax.swing.*;
Import java.awt.event.*;

public class Qqmain extends JFrame implements keylistener,actionlistener{
Components for passing data
JTextField txtmess = new JTextField ();
JTextArea txtcontent = new JTextArea ();
Construction method
Qqmain () {
Form basic information
This.setsize (800, 900);
This.setlocationrelativeto (NULL);
This.settitle ("Talking.ghoul");
Logo settings
Set the form logo
This.seticonimage (This.gettoolkit (). GetImage ("D:/LAB_2/PSB (one). jpg"));

New Component
Txtmess.setfont (New Font ("", 0, 36));
Txtcontent.setfont (New Font ("", 0, 36));
Txtcontent.seteditable (FALSE);

JButton btnsend = new JButton ("Send");
Btnsend.setfont (New Font ("Courier", Font.Bold, 26));

JComboBox cmbuser = new JComboBox ();

Registering for event monitoring
Btnsend.addactionlistener (this);

Set scroll bar
JScrollPane spcontent = new JScrollPane (txtcontent);

Small panel layout
JPanel Pansmall = new JPanel ();
Pansmall.setlayout (New GridLayout (1, 2));

Pansmall.add (Cmbuser);
Pansmall.add (Btnsend);

Large panel layout
JPanel panbig = new JPanel ();
Panbig.setlayout (New GridLayout (2, 1));

Panbig.add (txtmess);
Panbig.add (Pansmall);
Set up a large panel
Panbig.setpreferredsize (New Dimension (200, 100));


Layout form
This.setlayout (New BorderLayout ());

This.add (spcontent , borderlayout.center);
This.add (Panbig, Borderlayout.south);
}
public static void Main (string[] args) {
Qqmain w = new Qqmain ();
W.setvisible (TRUE);
}

@Override
public void keypressed (KeyEvent arg0) {

}
@Override
public void keyreleased (KeyEvent arg0) {}
@Override
public void keytyped (KeyEvent arg0) {}

@Override
public void actionperformed (ActionEvent arg0) {
System.out.println (arg0);
if (Arg0.getactioncommand (). Equals ("Send")) {
String mess = Txtmess.gettext ();
Txtmess.settext ("");
Txtcontent.append (' +mess+' \ n ');
}
}
}

Day 3:qqmain.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.