0

I am having difficulty calling other JApplets from main JApplet class when I run my code in the html tag on the university web server: I have a library database application designed as an JApplet, when I run it on eclipse and press the patron function button or Administrative function button, both JApplets from patron class and Administrative class work fine but when I run it on the university webserver and try to run it in the html tag and try to press the patron function or Administrative function button nothing happens no popup JFrame from any of those classes’ JApplets appear, I am using html class tags like this:

<center>
<applet code="library/MainMenu.class" height="400" width="500">
</applet>
</center>

Any sugguestion what should I add or eliminate to run the project or what am I doing wrong, I am kinda confused. Thank You Below is all the code I have so far:

package library;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

import library.PatronFunctionsMenu;

public class MainMenu extends JApplet implements ActionListener {

    private JFrame mainFrame;
    private JLabel mainMenulbl;
    private JButton patronFunctionBtn, administrativeFunctionBtn,
     quitBtn;
    private JPanel mainPanel;

    PatronFunctionsMenu patronJApplet;
    AdministrativeFunctionsMenu administrativeJApplet;



    public MainMenu() {
        mainFrame = new JFrame();
        mainPanel = new JPanel();
        mainMenulbl = new JLabel("MAIN MENU", SwingConstants.CENTER);
        mainMenulbl.setFont(new Font("Serif", Font.PLAIN, 18));
        patronFunctionBtn = new JButton("1-  Patron functions (ask for card number " +
                "then show submenu) " );
        administrativeFunctionBtn = new JButton("2-  Administrative functions");
        quitBtn = new JButton("3-  Quit");
        patronJApplet = new PatronFunctionsMenu();
        administrativeJApplet = new AdministrativeFunctionsMenu();
    }

    public void init() {

        mainFrame.setSize(600,400);
        mainFrame.setLayout(new BorderLayout());
        mainFrame.setTitle("MAIN MENU");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        mainFrame.add(mainPanel);
        mainPanel.setLayout(new GridLayout(10,1));
        //adding a jlabel
        //patronFunctionBtn.setSize(80, 291);
        mainPanel.add(mainMenulbl);

        //adding jbuttons
        mainPanel.add(patronFunctionBtn);
        mainPanel.add(administrativeFunctionBtn);
        mainPanel.add(quitBtn);
        mainFrame.setVisible(true);

        patronFunctionBtn.addActionListener(this);
        administrativeFunctionBtn.addActionListener(this);
        quitBtn.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        if (e.getSource() == patronFunctionBtn)

        { 
            JTextField textArea = new JTextField(15);
            int okCxl = JOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this),
                    textArea, "Enter Library Card Number and click ok!", JOptionPane.OK_CANCEL_OPTION);

                    if (okCxl == JOptionPane.OK_OPTION) {
                        String text = textArea.getText();


                        patronJApplet.start();
                        patronJApplet.init();
                        //JFrame patron = new JFrame();
                        //patron.findComponentAt(getLocation());
                        getContentPane().add(patronJApplet.getContentPane()); 
                        //setSize(800, 500); // not sure about this.  Usually better to call pack();
                        setVisible(true);
                    }


        }

        if (e.getSource() == administrativeFunctionBtn) {
        administrativeJApplet.start();
        administrativeJApplet.init();
        getContentPane().add(administrativeJApplet.getContentPane()); 
        setVisible(true);
    }

        if (e.getSource() == quitBtn)

        { 
            System.exit(0);
        }

    }


}

//PatronFunctionsMenu class
package library;

import java.applet.Applet;
import java.awt.*;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class PatronFunctionsMenu extends JApplet
        implements ActionListener {
    private JFrame patronFrame;
    private JPanel patronPanel;
    private JLabel patronLabel;
    private JButton bookCheckout;
    private JButton bookReturn;
    private JButton payFine;
    private JButton printLoanedBooksList;
    private JButton quit;

    public PatronFunctionsMenu() {

        patronFrame = new JFrame();
        patronPanel = new JPanel();
        patronLabel = new JLabel("PATRON FUNCTIONS MENU ", SwingConstants.CENTER);
        patronLabel.setFont(new Font("Serif", Font.PLAIN, 18));
        bookCheckout = new JButton("(1)-  Book Checkout");
        bookReturn = new JButton("(2)-  Book Return");
        payFine = new JButton("(3)-  Pay Fine");
        printLoanedBooksList = new JButton("(4)-  Print Loaned Books List");
        quit = new JButton("(5)-  Quit");
    }

    public void init(){

        /*
        // don't do this, just call pack() later
        //mainJFrame.setSize(600,400);
        mainJFrame.setLayout(new BorderLayout());
        mainJFrame.setTitle("Travel Agent System");
        mainJFrame.setBackground(Color.BLUE);


        mainJFrame.pack();
        // should be last.
        mainJFrame.setVisible(true);*/

        patronFrame.setSize(500, 400);
        patronFrame.setLayout(new BorderLayout());
        patronFrame.setTitle("PATRON FUNCTIONS MENU");
        patronFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        patronFrame.add(patronPanel);
        patronPanel.setLayout(new GridLayout(10,1));
        patronPanel.add(patronLabel, SwingConstants.CENTER);
        patronPanel.add(bookCheckout);
        patronPanel.add(bookReturn);
        patronPanel.add(bookReturn);
        patronPanel.add(payFine);
        patronPanel.add(printLoanedBooksList);
        patronPanel.add(quit);
        //patronFrame.pack();
        patronFrame.setVisible(true);

        quit.addActionListener(new ActionListener() {
             @Override
            public void actionPerformed(ActionEvent e) {
                 patronFrame.setVisible(false);
                 //PatronFunctionsMenu applet = new PatronFunctionsMenu();

                 }
        });

        patronPanel.add(quit);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

    }


}


//AdministrativeFunctionsMenu class
package library;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class AdministrativeFunctionsMenu extends JApplet
implements ActionListener {

    private JFrame administrativeFrame;
    private JPanel administrativePanel;

    private JLabel administrativeLabel;
    private JButton addBookButton;
    private JButton updateBookHoldingButton;
    private JButton searchBookButton;
    private JButton newPatronButton;
    private JButton printBranchInfoButton;
    private JButton quitAdministrativeButton;

    public AdministrativeFunctionsMenu() {

        administrativeFrame = new JFrame();
        administrativePanel = new JPanel();
        administrativeLabel = new JLabel("ADMINISTRATIVE FUNCTIONS MENU ", SwingConstants.CENTER);
        administrativeLabel.setFont(new Font("Serif", Font.PLAIN, 18));

        addBookButton = new JButton("(1)- Add a book");
        updateBookHoldingButton = new JButton("(2)- Update book holdings");
        searchBookButton =new JButton("(3)- Search book");
        newPatronButton = new JButton("(4)- New patron(add patron)");
        printBranchInfoButton = new JButton("(5) Print branch information");
        quitAdministrativeButton = new JButton("(6)- Quit");

    }

    public void init() {

        administrativeFrame.setSize(500, 400);
        administrativeFrame.setLayout(new BorderLayout());
        administrativeFrame.setTitle("ADMINISTRATIVE FUNCTIONS MENU");
        administrativeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        administrativeFrame.add(administrativePanel);
        administrativePanel.setLayout(new GridLayout(10,1));
        administrativePanel.add(administrativeLabel);
        administrativePanel.add(addBookButton);
        administrativePanel.add(updateBookHoldingButton);
        administrativePanel.add(searchBookButton);
        administrativePanel.add(newPatronButton);
        administrativePanel.add(printBranchInfoButton);

        administrativePanel.add(quitAdministrativeButton);

        administrativeFrame.setVisible(true);

        quitAdministrativeButton.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        if(e.getSource() == quitAdministrativeButton) {
            administrativeFrame.setVisible(false);
        }
    }

}

enter image description here

enter image description here

enter image description here

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Abdul
  • 37
  • 1
  • 5

0 Answers0