java 聊天界面 空布局,加滚动条panel.add(scroll);scroll.setBounds( , , , );怎么填?
packagegui;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.Act...
package gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import req.*;
public class ChatFrame extends JFrame {
private User from;
private User to;
JPanel jpanel=new JPanel();
JTextArea showArea = new JTextArea(10, 10);// 显示框
JScrollPane scroll = new JScrollPane(showArea);
public ChatFrame(final User from, final User to) {
this.setTitle("与"+to+"聊天");
this.from = from;
this.to = to;
this.setLayout(null);
this.setTitle("飞燕聊天工具");
this.setLocationRelativeTo(null);//窗口显示中央
showArea.setLineWrap(true);//激活自动换行功能
showArea.setWrapStyleWord(true);//激活断行不断字功能
showArea.setEditable(false);//不可编辑
//滚动条
scroll.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.getViewport().add(showArea);
final JTextArea inputArea = new JTextArea(1, 10);// 输入框
JButton sendButton = new JButton("发送");//发送按钮
//格式
jpanel.add(scroll);scroll.setBounds(20, 20, 340,180 );
this.add(showArea);showArea.setBounds(20, 20, 340, 180);
this.add(inputArea);inputArea.setBounds(20, 225, 250, 25);
this.add(sendButton);sendButton.setBounds(275, 225, 80, 25);
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text=inputArea.getText();
//封装了Chat(聊天)请求,并发送
Chat chat=new Chat(from, to, text);
chat.send();
showArea.append(from + ": " +"\n"+ text + "\n");
}
});
this.setSize(400, 300);
this.setVisible(true);
}
public User getFrom() {
return from;
}
public User getTo() {
return to;
}
} 展开
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import req.*;
public class ChatFrame extends JFrame {
private User from;
private User to;
JPanel jpanel=new JPanel();
JTextArea showArea = new JTextArea(10, 10);// 显示框
JScrollPane scroll = new JScrollPane(showArea);
public ChatFrame(final User from, final User to) {
this.setTitle("与"+to+"聊天");
this.from = from;
this.to = to;
this.setLayout(null);
this.setTitle("飞燕聊天工具");
this.setLocationRelativeTo(null);//窗口显示中央
showArea.setLineWrap(true);//激活自动换行功能
showArea.setWrapStyleWord(true);//激活断行不断字功能
showArea.setEditable(false);//不可编辑
//滚动条
scroll.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.getViewport().add(showArea);
final JTextArea inputArea = new JTextArea(1, 10);// 输入框
JButton sendButton = new JButton("发送");//发送按钮
//格式
jpanel.add(scroll);scroll.setBounds(20, 20, 340,180 );
this.add(showArea);showArea.setBounds(20, 20, 340, 180);
this.add(inputArea);inputArea.setBounds(20, 225, 250, 25);
this.add(sendButton);sendButton.setBounds(275, 225, 80, 25);
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text=inputArea.getText();
//封装了Chat(聊天)请求,并发送
Chat chat=new Chat(from, to, text);
chat.send();
showArea.append(from + ": " +"\n"+ text + "\n");
}
});
this.setSize(400, 300);
this.setVisible(true);
}
public User getFrom() {
return from;
}
public User getTo() {
return to;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询