import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example extends Applet implements ActionListener{ // #1
Button button; Label label;
public static void main(String[] args){ Frame win=new Frame("Example"); Example example=new Example(); win.add(example); example.init(); // #2 win.setSize(600,360); win.setVisible(true);
win.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
} public void init(){ // #3
button=new Button(" OK "); button.setBounds(280,200,100,20); button.addActionListener(this); label=new Label(); label.setBounds(260,100,200,20); add(button); add(label); } public void actionPerformed(ActionEvent e){ Object source=e.getSource(); if(source==button){ label.setText("Hello"); } } }
每次都不能全部显示出label标签上的文字,只有当窗体大小发生变化后,就可以完全显示出来.请问为什么会这样,如何来解决这个问题?
import java.awt.*;
import java.awt.event.*;
public class Example extends Applet implements ActionListener{ // #1
Button button; Label label;
public static void main(String[] args){ Frame win=new Frame("Example"); Example example=new Example(); win.add(example); example.init(); // #2 win.setSize(600,360); win.setVisible(true);
win.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
} public void init(){ // #3
button=new Button(" OK "); button.setBounds(280,200,100,20); button.addActionListener(this); label=new Label(); label.setBounds(260,100,200,20); add(button); add(label); } public void actionPerformed(ActionEvent e){ Object source=e.getSource(); if(source==button){ label.setText("Hello"); } } }
每次都不能全部显示出label标签上的文字,只有当窗体大小发生变化后,就可以完全显示出来.请问为什么会这样,如何来解决这个问题?
解决方案 »
- 接口
- 大家用过ImageIO这个类吗?其中的wirte 方法不是很明白。
- 急急急急急急急急急!! 问个关于Java多线程的synchronized的问题.
- 谁有“协议封装”的例子?
- 新手提问(急,在线等着):帮忙解决这个小程序!
- !!!!!!!!树的实现方式!!!!!!!!!!!!
- 急问html中parser 的用法
- 这段代码有什么问题,怎么老是执行不出结果
- Effective Java——并发 访问共享可变数据
- 本地服务器已经收到了请求,怎样回复微信服务器并不发信息给客户端或者说不给客户端做任何提示(后面是调用了客服接口来发消息的)?
- 散分
- 一个new StringTokenizer(s,",,");的问题.
public void setbounds(int a,int b,int width,int height),窗口调用该方法可以设置出现在屏幕上的初始位置,(a,b) 宽是width,高是height.