0

I want my button "insert", when clicked to open new applet/window and close existing applet. Please try to give me method which don't use concepts like JFrame and JButton etc. This is just front end. I'm going to use MONGODB at backend.

public class testd  extends Applet implements ActionListener,ItemListener
{
Button insert,update,delete,view,report,search;
TextField na,am,sts,nr;
TextArea t;
Label head;
Choice down;

Checkbox si,sr;
CheckboxGroup g;

Button submit,cancel;

public void init()
{
    setBackground(Color.white);
    setForeground(Color.black);
     this.setSize(new Dimension(500,500));
    setLayout(new FlowLayout());
    /////creating panel//////////////////
    Panel p1=new Panel(new GridLayout(3,5,7,4));
    head=new Label("        WELCOME        ");
    head.setFont(new Font("Courier",Font.BOLD,48));

    p1.add(head);

    add(head,"North");
/////////////////////creating menu///////////////////////    
    insert=new Button("INSERT");
    update=new Button("UPDATE");

    delete=new Button("DELETE");
    view=new Button("VIEW");
    report=new Button("REPORT");
    search=new Button("SEARCH");
 Font myFont = new Font("Arial", Font.ITALIC,30);
       insert.setFont(myFont);
       update.setFont(myFont);
       delete.setFont(myFont);
       view.setFont(myFont);
       report.setFont(myFont);
       search.setFont(myFont);

    down=new Choice();
    down.add("Machine Records");
    down.add("Machine Worksheet ");
    down.add("Machine Maintaince Record");
    down.add("Employee Record");
    down.add("Empoyee Worsheet");
    down.add("Raw Materail Record");
    down.add("Production Record");
    down.add("Account");
    down.setFont(myFont);



    //submit=new Button("SUBMIT");
    cancel=new Button("EXIT");

    add(insert);
    insert.addActionListener(this);
    add(update);
    add(view);
    add(search);
    add(delete);
    add(report);
    add(down);
    //add(submit);



    add(cancel);

    down.addItemListener((ItemListener) this);


}
@Override
public void actionPerformed(ActionEvent ae) {



        if(down.getSelectedItem().equals("Machine Records"))
            {
            if( ae.getSource()==insert)
               {
                  /*WHAT TO ADD HERE TO OPEN NEW APPLET/WINDOW/*
               }
            }


}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Mr AK
  • 43
  • 7
  • 2
    You can't and nor should you. An Applet is managed by the browser and you can't ask the browser to create more applets, that's not how this works. Instead, you should create each of your views in different `Component`'s/`Panel`'s and switch between them. Next, why are you using a API which was circumvented some 15+ years ago? And with ever modern browser basically actively blocking applets, why are you using them now? There are simply any number of options which are both simpler and provide better functionality. – MadProgrammer Sep 23 '15 at 04:01
  • 1
    You could have a look at [this](http://stackoverflow.com/questions/32685555/how-can-i-make-an-applet-call-and-run-another-applet/32685631#32685631) which expends the concept in a little more detail – MadProgrammer Sep 23 '15 at 04:01
  • 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. 3) +1 to all the advice of @MadProgrammer. – Andrew Thompson Sep 23 '15 at 13:30
  • 1
    @MadProgrammer *"..and switch between them."* For that you might use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson Sep 23 '15 at 13:32
  • 1
    @AndrewThompson Which was mentioned in example I linked ;) – MadProgrammer Sep 23 '15 at 21:02
  • @MadProgrammer My bad. :P – Andrew Thompson Sep 24 '15 at 00:09
  • 1
    @AndrewThompson I "hinted" at it, I just didn't mention it directly, glad you did though ;) – MadProgrammer Sep 24 '15 at 00:09

0 Answers0