1

I wish that when someone presses 'Search' button a new set of buttons must appear on same applet.I wrote following code(else clause is missing but that is not an issue):

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();
    }


}
}

Please help.I wish if page=1 then only two buttons must appear.and if page=2 new set of buttons must replace those buttons

  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Mar 05 '15 at 02:02

0 Answers0