0

Good Day-

I'm working on JApplets in which I have two tabbedPanel. Now for the first tabbed I need to further divide the parent JPanel into two parts. For this I created two sub panels and also have used the JSplitPane class to split those into two parts.

  1. eastPanel
  2. westPanel

The windows looks like the following:

enter image description here

This is Resizeable as we can see the maximize button is enable. I have tried to set this method setResizeable() but I think it's only available for JFRAME.

The desired UI which I'm try to create is as following:

enter image description here

What I need is to restrict its size so that it won't be maximize anymore and the content is placed as it is in the JPanel. Could you please guide me which approach I should follow to achieve the desired results? Furthermore the source is as following:

    public class CreatePanel extends JPanel
 {
   private Vector athleteList;
   private JButton button1;
   private CountPanel cPanel;
   private TextField firstName;
   private TextArea textArea;
 //Constructor initializes components and organize them using certain layouts
 public CreatePanel(Vector athleteList, CountPanel cPanel)
  {
    this.athleteList = athleteList;
    this.cPanel = cPanel;

    //inner Jpanels to Split the parent panel
    JPanel eastPanel = new JPanel();
    JPanel westPanel = new JPanel();

    button1 = new JButton("Create an Athlete");
    textArea = new TextArea("No Athlete");
    textArea.setEditable(false);

    eastPanel.setBackground(Color.RED);
    westPanel.setBackground(Color.BLUE);
    eastPanel.add(button1);
    /* p1.add(firstName);
    p2.add(textArea);*/

    JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    sp.setResizeWeight(0.5);
    sp.setDividerSize(0);
    sp.add(eastPanel);
    sp.add(westPanel);
    //organize components here
    setLayout( new GridLayout(1, 2));    

//    add(firstName,BorderLayout.WEST);
    add(sp);


  }


  //ButtonListener is a listener class that listens to
  //see if the button "Create an Athlete" is pushed.
  //When the event occurs, it adds an athlete using the information
  //entered by a user.
  //It also performs error checking.
  private class ButtonListener implements ActionListener
   {
    public void actionPerformed(ActionEvent event)
     {

         //TO BE COMPLETED

     } //end of actionPerformed method
  } //end of ButtonListener class

} 

DriveClass

public class Test extends JApplet
 {

   private int APPLET_WIDTH = 500, APPLET_HEIGHT = 400;

   private JTabbedPane tPane;
   private CreatePanel createPanel;
   private CountPanel countPanel;
   private Vector athleteList;

   //The method init initializes the Applet with a Pane with two tabs
   public void init()
    {
     //list of athletes to be used in every panel
    athleteList = new Vector();

     //register panel uses the list of athletes
     countPanel = new CountPanel(athleteList);

     createPanel = new CreatePanel(athleteList, countPanel);

     //create a tabbed pane with two tabs
     tPane = new JTabbedPane();
     tPane.addTab("Athlete Creation", createPanel);
     tPane.addTab("Medal Count", countPanel);
     getContentPane().add(tPane);
     setSize (APPLET_WIDTH, APPLET_HEIGHT); //set Applet size
     setPreferredSize(new Dimension(APPLET_WIDTH, APPLET_HEIGHT));
     setMaximumSize(this.getPreferredSize());
     setMinimumSize(this.getPreferredSize());
    }
}

Help will be appreciated.Many Thanks

yole
  • 92,896
  • 20
  • 260
  • 197
M A.
  • 949
  • 2
  • 12
  • 29
  • 3
    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) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free). 3) An applet's size is set in the HTML. The screenshots above show the applet viewer. It is not really relevant except during development. – Andrew Thompson Sep 17 '16 at 08:35
  • @AndrewThompson these are the directives and I have to create this using the Java applets. – M A. Sep 17 '16 at 08:43
  • *"these are the directives"* From who? 'I was told to' is simply not enough to get my active help. Now is a good time for more words, not less. – Andrew Thompson Sep 17 '16 at 08:55
  • @AndrewThompson - Obviously from instructor. I wish to use the JFrame instead of this or use any third party plugin to create the UI via drag n drop. – M A. Sep 17 '16 at 09:00
  • 1
    *"Obviously from instructor."* It's obvious to me, only after you tell me. So, what did they say when you referred them to the first link I offered? *"or use any third party plugin to create the UI via drag n drop"* I don't see how that relates to anything in the question or any of my comments. But since you mentioned it. D'n'D designed GUIs are rubbish unless the programmer first understands how to use layouts, and otherwise create the code without them. With that understanding, they can make light work of creating an applet, a frame or a panel that might go in either (or a window, or dialog) – Andrew Thompson Sep 17 '16 at 09:09
  • I don't see the need for `JSplitPane`; try [`GroupPanel`](http://stackoverflow.com/a/8504753/230513) on the left; build a [hybrid](http://stackoverflow.com/a/12449949/230513) if you're not sure. – trashgod Sep 17 '16 at 09:11
  • @AndrewThompson - I agree, I will refer him the first link which you have offered but these are the course outline so in anycase we have to use those while working with the assignment or HW. – M A. Sep 17 '16 at 09:18
  • 1
    The course should be changed *now* rather than later. That instructor should not be teaching until they understand the difficulties they are forcing on the students. And you can tell the instructor that advice comes direct from the guy that wrote the blog article, is the top ranked provider of answers for both the `Applet` and `JApplet` tags, and wrote the info. pages on each. Bottom line is, even ***I've*** abandoned applets, so anyone forced to develop them is in for a hard time. If the instructor is going to be difficult about it, challenge them to 'write an intro applet, and deploy it so.. – Andrew Thompson Sep 17 '16 at 09:29
  • .. the class can visit it on the web. After they go through that experience (even assuming they can achieve it) I'd bet they'd have changed their tune on specifying it 'must be an applet'. – Andrew Thompson Sep 17 '16 at 09:30
  • Since a [JApplet is started from HTML](https://docs.oracle.com/javase/tutorial/deployment/applet/html.html) with the width and height specified in the HTML, there's no resizing to worry about. Good luck finding a browser that still displays applets. – Gilbert Le Blanc Sep 17 '16 at 13:29
  • OP must be from a school in India, or doing IB comp sci. They are notorious for using outdated syllabus. Their school is still teaching StringTokenizer. – user3437460 Sep 20 '16 at 01:56

0 Answers0