Topic: 百思不得其解的问题 |
Print this page |
1.百思不得其解的问题 | Copy to clipboard |
Posted by: kingfhr Posted on: 2007-12-08 10:29 package tcp客户端e; import java.awt.*; import java.awt.Container; import javax.swing.*; public class Cliente extends JFrame{ JTextArea t1=new JTextArea(10,10); JTextField t2=new JTextField(20); JButton b1=new JButton("send"); JButton b2=new JButton("连接服务器"); JScrollPane jsp=new JScrollPane(t1); public Cliente(){ JPanel p1=new JPanel(); p1.add(t2); p1.add(b1); JPanel p2=new JPanel(); p2.add(b2); this.getContentPane().setLayout(new BorderLayout()); Container contentPane=this.getContentPane(); contentPane.add(jsp,BorderLayout.CENTER); contentPane.add(p2,BorderLayout.NORTH); contentPane.add(p1,BorderLayout.SOUTH); setTitle("客户端e"); setVisible(true); setSize(340,300); } public static void main(String[] args) { Cliente mainFrame=new Cliente(); } } 上面这段程序为什么显示界面一片空白?各位谁有时间帮忙看看,不胜感激! |
2.Re:百思不得其解的问题 [Re: kingfhr] | Copy to clipboard |
Posted by: grubby__4k Posted on: 2007-12-09 17:56 那是因为你没调整好坐标 还有在340,300中显示的按钮位置没定义 如果你最大化该窗口 就会发现有按钮 |
3.Re:百思不得其解的问题 [Re: kingfhr] | Copy to clipboard |
Posted by: kingfhr Posted on: 2007-12-13 10:39 我试过改窗口大小,也试过最大化运行窗口还是不行 后来知道要把 setVisible(true); setSize(340,300);调换位置 |
4.Re:百思不得其解的问题 [Re: kingfhr] | Copy to clipboard |
Posted by: kantery Posted on: 2008-05-16 16:18 我改了改,你看看这个,是你想要的那个吗? import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class Cliente extends JFrame { JTextArea t1; JTextField t2; JButton b1; JButton b2; JScrollPane jsp; public Cliente() { t1 = new JTextArea(10, 10); t2 = new JTextField(20); b1 = new JButton("send"); b2 = new JButton("连接服务器"); jsp = new JScrollPane(t1); Container container = this.getContentPane(); JPanel p1 = new JPanel(); p1.add(t2); p1.add(b1); JPanel p2 = new JPanel(); p2.add(b2); container.add(jsp, BorderLayout.CENTER); container.add(p1, BorderLayout.NORTH); container.add(p2, BorderLayout.SOUTH); this.setTitle("客户端e"); this.setSize(340, 300); this.setVisible(true); } public static void main(String args[]) { Cliente client = new Cliente(); client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } |
5.Re:百思不得其解的问题 [Re: kingfhr] | Copy to clipboard |
Posted by: kantery Posted on: 2008-05-16 16:40 我改了改,你看看这个,是你想要的那个吗? import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class Cliente extends JFrame { JTextArea t1; JTextField t2; JButton b1; JButton b2; JScrollPane jsp; public Cliente() { t1 = new JTextArea(10, 10); t2 = new JTextField(20); b1 = new JButton("send"); b2 = new JButton("连接服务器"); jsp = new JScrollPane(t1); Container container = this.getContentPane(); JPanel p1 = new JPanel(); p1.add(t2); p1.add(b1); JPanel p2 = new JPanel(); p2.add(b2); container.add(jsp, BorderLayout.CENTER); container.add(p1, BorderLayout.NORTH); container.add(p2, BorderLayout.SOUTH); this.setTitle("客户端e"); this.setSize(340, 300); this.setVisible(true); } public static void main(String args[]) { Cliente client = new Cliente(); client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |