JLabel 呈現的困擾 |
尚未結案
|
ParchiYoung
一般會員 發表:2 回覆:3 積分:1 註冊:2003-04-09 發送簡訊給我 |
此程式的用途是當按下上方的按鈕,在底下 JPanel 容器內增加一個 JLabel 元件。我測試過當按下按鈕時,JPanel 容器是會增加一個JLabel 元件,但要看到此 JLabel 元件須要改變視窗的大小。請各位大大幫忙一下…,如何按下按鈕時,立即能在下方JPanel 看到 JLabel 元件,謝謝。 import java.awt.*;
import java.awt.event.*;
import javax.swing.*; public class ShowJLabel extends JFrame{
JButton button = new JButton("秀一下");
JPanel panel = new JPanel();
Container content; public ShowJLabel(){
super("Frame Title");
content = this.getContentPane();
content.setLayout(null);
button.setBounds(10,10,100,30);
button.addActionListener(new ShowJLabel_button_actionAdapter(this));
content.add(button);
panel.setBounds(0,45,120,80);
panel.setBorder(BorderFactory.createRaisedBevelBorder());
content.add(panel);
this.setSize(new Dimension(130,170));
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void button_actionPerformed(ActionEvent e){
panel.add(new Label("我秀我秀!!"));
}
public static void main(String args[]){
new ShowJLabel();
}
} class ShowJLabel_button_actionAdapter implements java.awt.event.ActionListener{
ShowJLabel SJL;
ShowJLabel_button_actionAdapter(ShowJLabel SJL){
this.SJL = SJL;
}
public void actionPerformed(ActionEvent e){
SJL.button_actionPerformed(e);
}
}
|
neoart
版主 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |