java布局问题
importjava.awt.event.*;importjavax.swing.*;importjava.io.*;importjava.awt.BorderLayou...
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import java.awt.LayoutManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Container;
public class ChatFrame extends JFrame implements ActionListener{
private String name;
private JButton jb_send,jb_off;
private JTextArea jta;
private JTextField jtf;
private PrintWriter pw;
private JPanel jp=new JPanel();
public ChatFrame(String name,PrintWriter pw){
super(name);
this.setSize(440,400);//the size of the window
this.setLocation(150, 150);//where the window appear
this.setDefaultCloseOperation(3);//the method of c
this.name=name;
this.pw=pw;
jb_send=new JButton("send");
jb_off=new JButton("off");
jb_send.addActionListener(this);
jb_off.addActionListener(this);
jta=new JTextArea(15,35);
jtf=new JTextField(20);
jta.setEditable(false);
jp.add(new JScrollPane(jta),"center");
jp.add(jtf);
jp.add(jb_send);
jp.add(jb_off);
this.add(jp,"South");
this.setVisible(true);
}
public void receive(String s){
jta.append(s+"\n");
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="send"){
if(pw!=null){
pw.println(name+" say:"+jtf.getText());
jta.append("I say: "+jtf.getText()+"\n");
jtf.setText("");
}else{
jta.append("You are already off\n");
}
}else{
if(pw!=null){
pw.println(this.name +" is off");
pw.println("bye");
pw=null;
jta.append("I'm off\n");
}else{
jta.append("You are already off\n");
}
我实在是被这个布局搞到烦了。这是我在改的一个网络编程的程序。
但是不管怎么搞布局就是个问题。我的想法是让这个框的上方显示聊天窗口。然后窗口的下面显示输入,输入的右边显示那两个按钮。就像QQ一样。哪个好心人帮个忙吧。我从九点一直搞到现在。崩溃了都
}
}
} 展开
import javax.swing.*;
import java.io.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import java.awt.LayoutManager;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Container;
public class ChatFrame extends JFrame implements ActionListener{
private String name;
private JButton jb_send,jb_off;
private JTextArea jta;
private JTextField jtf;
private PrintWriter pw;
private JPanel jp=new JPanel();
public ChatFrame(String name,PrintWriter pw){
super(name);
this.setSize(440,400);//the size of the window
this.setLocation(150, 150);//where the window appear
this.setDefaultCloseOperation(3);//the method of c
this.name=name;
this.pw=pw;
jb_send=new JButton("send");
jb_off=new JButton("off");
jb_send.addActionListener(this);
jb_off.addActionListener(this);
jta=new JTextArea(15,35);
jtf=new JTextField(20);
jta.setEditable(false);
jp.add(new JScrollPane(jta),"center");
jp.add(jtf);
jp.add(jb_send);
jp.add(jb_off);
this.add(jp,"South");
this.setVisible(true);
}
public void receive(String s){
jta.append(s+"\n");
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="send"){
if(pw!=null){
pw.println(name+" say:"+jtf.getText());
jta.append("I say: "+jtf.getText()+"\n");
jtf.setText("");
}else{
jta.append("You are already off\n");
}
}else{
if(pw!=null){
pw.println(this.name +" is off");
pw.println("bye");
pw=null;
jta.append("I'm off\n");
}else{
jta.append("You are already off\n");
}
我实在是被这个布局搞到烦了。这是我在改的一个网络编程的程序。
但是不管怎么搞布局就是个问题。我的想法是让这个框的上方显示聊天窗口。然后窗口的下面显示输入,输入的右边显示那两个按钮。就像QQ一样。哪个好心人帮个忙吧。我从九点一直搞到现在。崩溃了都
}
}
} 展开
展开全部
Jpanl自己默认的布局是流布局(flowlayout),Jfram默认布局为边框布局(BorderLayout)要想像QQ一样的话,我感觉应该多建立几个Jpanl 边框布局放置到Jfram上,几个按钮用流布局,这样应该可以的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我觉得netbeans做swing挺好的,起码不用把精力全放在布局上了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询