Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8976687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:16+00:00 2026-06-15T19:12:16+00:00

I have to build a small Java applet for a project. I have previously

  • 0

I have to build a small Java applet for a project. I have previously never used applets. Hence I don’t know much about the various inbuilt functions available. The layout of this applet is as below:

  1. The screen is divided into 3 parts
  2. Top most part will have a set of buttons and text boxes
  3. Middle part and bottom part will be displaying different images
  4. These Images can vary in size when the program is run each time (Hence it requires scroll bars in case the image goes out of the screen)

Till now I have succeeded in partitioning the screen and creating separate panels for the each part and adding the corresponding components in them.

Problem:

The bottom image is not completely visible. And also scroll bars are not appearing for each Image when it does not fit into the panel.

I tried using setSize(), setMinimumSize() methods but it does not produce any changes in the output. Can you please help me with the above problem?

This is what I have done till now:

/*<applet code=DOSlayout.java width=400 height=400>
</applet>*/ 

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

public class DOSlayout extends JApplet implements ActionListener {

    Button ViewButton;
    Panel1 Top;
    Panel2 LeftSide;
    Panel3  RightSide;
    Label l1,l2,l3;
    
    Image img;
    
    public void init() {

        setSize(400,400);
        setLayout(new BorderLayout());
        
        Top = new Panel1();
        LeftSide = new Panel2();
        RightSide = new Panel3();
        
        Top.setSize(getSize().width, getSize().height/3);
        LeftSide.setSize(getSize().width,getSize().height/3); 
        RightSide.setSize(getSize().width,getSize().height/3);

//RightSide.setMinimumSize (new Dimension(400, 10000));
        
        add(Top, BorderLayout.NORTH);
        add(LeftSide, BorderLayout.CENTER);
        add(RightSide, BorderLayout.SOUTH);
        
        ViewButton = new Button("View");

        
        l1 = new Label("North");
        l2 = new Label("East");
        l3 = new Label("West");
        
                    
        Top.add(ViewButton);
        
        
        Top.add(l1);        
        //LeftSide.add(l2);
        //RightSide.add(l3);
        
        ViewButton.addActionListener(this);     
    }
    
    
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
        
    }

class Panel1 extends JPanel {

Panel1() {
super();
}

public void paint(Graphics g) {
}

}

class Panel2 extends JPanel {

Panel2() {
super();
}

   private Image img;

   public void init()
   {
      img = null;
   }
   public void loadImage()
   {
      try
      { 
         img = getImage(getCodeBase(), "input1.png");
      }
      catch(Exception e) { }
   }
   public void paint(Graphics g)
   {
      if (img == null)
         loadImage();
      g.drawImage(img, 0, 0, this);
      //g.drawImage(img,0,0,(int)getBounds().getWidth(), (int)getBounds().getHeight(),this);
   }

}

class Panel3 extends JPanel {

Panel3() {
super();
}

   private Image img;

   public void init()
   {
      img = null;
//setSize(400,400);
   }
   public void loadImage()
   {
      try
      { 
         img = getImage(getCodeBase(), "input2.png");
      }
      catch(Exception e) { }
   }
   public void paint(Graphics g)
   {
      if (img == null)
         loadImage();
      g.drawImage(img, 0, 0, this);
//g.drawImage(img,0,0,(int)getBounds().getWidth(), (int)getBounds().getHeight(),this);
   }
}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:12:17+00:00Added an answer on June 15, 2026 at 7:12 pm

    Start with the container used in ImageViewer. It centers the image inside a scroll-pane whose scroll-bars appear reliably.

    Further tips

    1. “I have previously never used applets.” That is ominous, given applets are tougher to develop & deploy than frames. I suggest develop this first in a JFrame (then launch the frame from a link using Java Web Start). Only after seeing the frame launched using JWS should you consider using an applet. By that stage, any ‘conversion’ needed will be much simpler.
    2. Don’t ever call setSize(..) in an applet. The size is in the HTML.
    3. Don’t mix Swing and AWT components unless necessary, use all Swing.
    4. It is typically a bad idea to set the sizes (preferred, max or min) of any components.
    5. Please learn common Java naming conventions (specifically the case used for the names) for class, method & attribute names & use it consistently.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small maven project that build a java jar file. I added
i have a small java project i want to build using a makefile, the
I have have a small prototype game in java where players can build their
I've built a small applet and I have all the .java class files. How
I have configured a Maven build for a very small GWT project I'm having.
I have a small Java project in a version control system (git), shared by
If I have small Blackberry project with just 10 or less java class files,
I'm trying to build a large Java project by building many small, modular projects.
i have build a small function whose work to get value in alert box
i have build a small test app in Flash Pro 5.5 overlayed with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.