程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestInput extends Container
{
int x=0;
int Height=0,Width=0;
TextField textfield;
JPanel panel;
String text="";
Dimension dt;
Dimension dc;
public TestInput()
{
super();
panel=new JPanel();
textfield=new TextField(15); textfield.setLocation(200,0);
panel.add(textfield);
this.add(panel);
}
public int getWidth()
{
return Width=301;
}
public int getHeight()
{
return Height=25;
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestFrame extends JFrame
{
public TestFrame()
{
JFrame f=new JFrame("Test");
TestInput input=new TestInput();
input.setLocation(0,20);
System.out.println("Input's width: "+input.getWidth()+","+"Input's heitht: "+input.getHeight());
this.setLayout(new BorderLayout());
getContentPane().add("North",new Label("This is a test label!This is a test label!These are books for the students!"));
getContentPane().add("Center",input);
getContentPane().add("South",new Label("This is a test label!"));
}
public static void main(String args[])
{
TestFrame app=new TestFrame();
app.setSize(500,400);
app.setVisible(true);
app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
显示出来以后,那个TextField总是向左偏移了一些,显示不完全。不明白为什么?
请各位大侠赐教!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestInput extends Container
{
int x=0;
int Height=0,Width=0;
TextField textfield;
JPanel panel;
String text="";
Dimension dt;
Dimension dc;
public TestInput()
{
super();
panel=new JPanel();
textfield=new TextField(15); textfield.setLocation(200,0);
panel.add(textfield);
this.add(panel);
}
public int getWidth()
{
return Width=301;
}
public int getHeight()
{
return Height=25;
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestFrame extends JFrame
{
public TestFrame()
{
JFrame f=new JFrame("Test");
TestInput input=new TestInput();
input.setLocation(0,20);
System.out.println("Input's width: "+input.getWidth()+","+"Input's heitht: "+input.getHeight());
this.setLayout(new BorderLayout());
getContentPane().add("North",new Label("This is a test label!This is a test label!These are books for the students!"));
getContentPane().add("Center",input);
getContentPane().add("South",new Label("This is a test label!"));
}
public static void main(String args[])
{
TestFrame app=new TestFrame();
app.setSize(500,400);
app.setVisible(true);
app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
显示出来以后,那个TextField总是向左偏移了一些,显示不完全。不明白为什么?
请各位大侠赐教!
解决方案 »
- java折半查找问题
- 请教java中关于exec调用cmd的问题
- netbeans问题求助!
- java面试
- 怎么去掉IE中applet对话框下面的applet window字符串
- !!!关于字符串的连接问题!!!!!!!!!!!!!!!
- JOptionPane.showMessageDialog(..)字体,以及label内容能改吗???
- 超級菜鳥等待你的指點!給分後
- 刚下载jb5,我想要快速入门,请大虾花最少的时间解答但对YOU是小菜的问题?请用具体的操作教我做一个简单的数据库应用。当然只是说步鄹(从新建项目到打包运性,一定要详细罗,)代码不必了。
- 请问:用Apple中URLConnection.getOutputStream获得的输出流如何写进该URL文件?
- 在任何情况下都不需要new String()???
- 线程问题,快来看看
import javax.swing.*;class TestInput extends JPanel {
int x = 0; int Height = 0, Width = 0; TextField textfield; JPanel panel; String text = ""; Dimension dt; Dimension dc; public TestInput() {
super();
panel = new JPanel();
panel.setLayout(new FlowLayout());
textfield = new TextField(15);
panel.add(textfield);
this.add(panel);
} public int getWidth() {
return Width = 301;
} public int getHeight() {
return Height = 25;
}
}public class JustTest extends JFrame { public JustTest() {
super("Test"); TestInput input = new TestInput();
System.out.println("Input's width: " + input.getWidth() + ","
+ "Input's heitht: " + input.getHeight()); this.setLayout(new BorderLayout());
add("North",new Label("This is a test label!"));
add("Center", input);
add("South", new Label("This is a test label too!")); setSize(500, 400);
setVisible(true);
} public static void main(String args[]) {
new JustTest();
}
}