按下按钮时无法刷新小程序并且多次显示相同的按钮?

时间:2015-03-04 16:56:35

标签: java button applet

我希望当有人按下“搜索”按钮时,一组新的按钮必须出现在同一个applet上。我写了下面的代码(else子句丢失,但这不是问题):

package database_connect;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
/* <applet code="Home" width=300 height=100>   
</applet>
*/
public class PDFsup extends Applet implements ActionListener {
int page;
@Override
public void init() {
    Color c1= new Color(219,182,182);
    Color c2= new Color(95,133,170);
    setBackground(c1);
    setForeground(c2);
}
public void paint(Graphics g){
    start();
    Font f=new Font("ICON",Font.BOLD,100);
    setFont(f);
    page=1;
    g.drawString("PDFsup", 48,24);
    Font f1=new Font("Buttons",Font.BOLD,20);
    setFont(f1);
    if(page==1){
        Button Search= new Button ("SEARCH PDF");
        Button Upload=new Button("UPLOAD PDF");
        add(Search);
        add(Upload);
        Search.addActionListener(this);
        Upload.addActionListener(this);
        stop();
    }
    start();
    if(page==2){
        Button Keyword= new Button ("SEARCH By KEYWORDS");
        Button Title=new Button("Search By TITLE");
        add(Keyword);
        add(Title);
        Keyword.addActionListener(this);
        Title.addActionListener(this);
        stop();
    }

}

@Override
public void actionPerformed(ActionEvent ae) {
    String s=ae.getActionCommand();
    if(s.equals("SEARCH PDF")){
        page=2;
        repaint();
    }


}
}

请帮忙。我希望如果页面= 1,那么只有两个按钮必须出现。如果页面= 2,则新的按钮组必须替换这些按钮

0 个答案:

没有答案