码迷,mamicode.com
首页 > 编程语言 > 详细

day 3: QQMain.java

时间:2016-10-24 23:19:18      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:center   jtextarea   listener   false   send   south   ttext   logo   editable   

技术分享

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

public class QQMain extends JFrame implements KeyListener,ActionListener{
//用于传递数据的组件
JTextField txtMess = new JTextField();
JTextArea txtContent = new JTextArea();
//构造方法
QQMain(){
//窗体基本信息
this.setSize(800 , 900);
this.setLocationRelativeTo(null);
this.setTitle("Talking.GHOUL");
//logo设置
//设置窗体LOGO
this.setIconImage(this.getToolkit().getImage("D:/lab_2/psb (11).jpg"));

//new组件
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();

//注册事件监听
btnSend.addActionListener(this);

//设置滚动条
JScrollPane spContent = new JScrollPane(txtContent);

//布置小面板
JPanel panSmall = new JPanel();
panSmall.setLayout(new GridLayout(1 , 2));

panSmall.add(cmbUser);
panSmall.add(btnSend);

//布置大面板
JPanel panBig = new JPanel();
panBig.setLayout(new GridLayout(2 , 1));

panBig.add(txtMess);
panBig.add(panSmall);
//设置大面板
panBig.setPreferredSize(new Dimension(200 , 100));


//布置窗体
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

标签:center   jtextarea   listener   false   send   south   ttext   logo   editable   

原文地址:http://www.cnblogs.com/xkxf/p/5994892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!