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 6775499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:54:50+00:00 2026-05-26T15:54:50+00:00

this is the class who i use to load the images, i use the

  • 0

this is the class who i use to load the images, i use the constructor to call the metod load who load the images in the array percorso.

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;

class Track extends Component {
   Image[] percorso;
   String path;
   int n;
   int x;
   int y;

   public Track(String path, int n) {
      int i;
      this.path = path;
      this.n = n;
      this.percorso = new Image[n];
      for (i = 0; i < n; i++) {
         this.percorso[i] = load(path, n, i);
         repaint();
      }
   }

   public final Image load(String path, int n, int i) {
      Toolkit tool = Toolkit.getDefaultToolkit();
      String dot = ".jpg";
      path = this.path;
      path = path + Integer.toString(i) + dot;
      Image img = tool.getImage(path);
      try {
         MediaTracker track = new MediaTracker(this);
         track.addImage(img, 0);
         track.waitForID(0);
      } catch (InterruptedException e) {
         System.out.println("Image not loaded");
      }
      return (img);
   }

   @Override
   public void paint(Graphics g) {
      int i;
      g.drawImage(percorso[1], x, y, this);
   }
}

This is the class where i create the gui, and i try to add the images to the jlayeredpane, but it’s didn’t work.

public class Gui extends javax.swing.JFrame {

   /** Creates new form GUI */
   public Gui() {
      initComponents();
   }

   /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {

      background = new javax.swing.JLayeredPane();
      testata = new javax.swing.JLabel();
      nuova = new javax.swing.JLabel();
      selectrack = new javax.swing.JLabel();
      track1 = new javax.swing.JLabel();
      track2 = new javax.swing.JLabel();
      track3 = new javax.swing.JLabel();
      track4 = new javax.swing.JLabel();
      track5 = new javax.swing.JLabel();
      track5.setVisible(false);
      track6 = new javax.swing.JLabel();
      track6.setVisible(false);
      track7 = new javax.swing.JLabel();
      track7.setVisible(false);
      track8 = new javax.swing.JLabel();
      track8.setVisible(false);
      track9 = new javax.swing.JLabel();
      track9.setVisible(false);
      track10 = new javax.swing.JLabel();
      track10.setVisible(false);
      behind = new javax.swing.JLabel();
      behind.setVisible(false);
      traccy = new javax.swing.JLabel();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      testata.setFont(new java.awt.Font("Tahoma", 0, 36));
      testata.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      testata.setText("Thosa Racing");
      testata.setBounds(90, 0, 220, 44);
      background.add(testata, javax.swing.JLayeredPane.DEFAULT_LAYER);

      nuova.setFont(new java.awt.Font("Tahoma", 0, 18));
      nuova.setText("Nuova");
      nuova.addMouseListener(new java.awt.event.MouseAdapter() {
         public void mouseClicked(java.awt.event.MouseEvent evt) {
            nuovaMouseClicked(evt);
         }
      });
      nuova.setBounds(160, 140, 50, 22);
      background.add(nuova, javax.swing.JLayeredPane.DEFAULT_LAYER);

      selectrack.setVisible(false);
      selectrack.setFont(new java.awt.Font("Tahoma", 0, 24));
      selectrack.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      selectrack.setText("Scegli il tracciato");
      selectrack.setBounds(110, 10, 177, 29);
      background.add(selectrack, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track1.setVisible(false);
      track1.setFont(new java.awt.Font("Tahoma", 0, 24));
      track1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track1.setText("1");
      track1.addMouseListener(new java.awt.event.MouseAdapter() {
         public void mouseClicked(java.awt.event.MouseEvent evt) {
            track1MouseClicked(evt);
         }
      });
      track1.setBounds(50, 50, 13, 29);
      background.add(track1, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track2.setVisible(false);
      track2.setFont(new java.awt.Font("Tahoma", 0, 24));
      track2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track2.setText("2");
      track2.setBounds(120, 50, 13, 29);
      background.add(track2, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track3.setVisible(false);
      track3.setFont(new java.awt.Font("Tahoma", 0, 24));
      track3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track3.setText("3");
      track3.setBounds(190, 50, 13, 29);
      background.add(track3, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track4.setVisible(false);
      track4.setFont(new java.awt.Font("Tahoma", 0, 24));
      track4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track4.setText("4");
      track4.setBounds(250, 50, 13, 29);
      background.add(track4, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track5.setFont(new java.awt.Font("Tahoma", 0, 24));
      track5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track5.setText("5");
      track5.setBounds(320, 50, 13, 29);
      background.add(track5, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track6.setFont(new java.awt.Font("Tahoma", 0, 24));
      track6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track6.setText("6");
      track6.setBounds(50, 110, 13, 29);
      background.add(track6, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track7.setFont(new java.awt.Font("Tahoma", 0, 24));
      track7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track7.setText("7");
      track7.setBounds(120, 110, 13, 29);
      background.add(track7, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track8.setFont(new java.awt.Font("Tahoma", 0, 24));
      track8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track8.setText("8");
      track8.setBounds(190, 110, 13, 29);
      background.add(track8, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track9.setFont(new java.awt.Font("Tahoma", 0, 24));
      track9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track9.setText("9");
      track9.setBounds(250, 110, 13, 29);
      background.add(track9, javax.swing.JLayeredPane.DEFAULT_LAYER);

      track10.setFont(new java.awt.Font("Tahoma", 0, 24));
      track10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      track10.setText("10");
      track10.setBounds(320, 110, 26, 29);
      background.add(track10, javax.swing.JLayeredPane.DEFAULT_LAYER);

      behind.setFont(new java.awt.Font("Tahoma", 0, 18));
      behind.setText("Behind");
      behind.addMouseListener(new java.awt.event.MouseAdapter() {
         public void mouseClicked(java.awt.event.MouseEvent evt) {
            behindMouseClicked(evt);
         }
      });
      behind.setBounds(10, 260, 54, 22);
      background.add(behind, javax.swing.JLayeredPane.DEFAULT_LAYER);
      traccy.setBounds(0, 0, 400, 300);
      background.add(traccy, javax.swing.JLayeredPane.DEFAULT_LAYER);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
            getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(layout.createParallelGroup(
            javax.swing.GroupLayout.Alignment.LEADING).addComponent(background,
            javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE));
      layout.setVerticalGroup(layout.createParallelGroup(
            javax.swing.GroupLayout.Alignment.LEADING).addComponent(background,
            javax.swing.GroupLayout.Alignment.TRAILING,
            javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE));

      pack();
   }// </editor-fold>

   private void nuovaMouseClicked(java.awt.event.MouseEvent evt) {
      // Disabilita menu principale
      byte d = 1;
      disable(d);
   }

   private void behindMouseClicked(java.awt.event.MouseEvent evt) {
      // Torna al menu principale
      byte d = 2;
      disable(d);
   }

   private void track1MouseClicked(java.awt.event.MouseEvent evt) {
      trackMDisable(false);
      Track tracciato1 = new Track("src/track/m", 5);
      background.add(tracciato1);

   }

   // Metodo dis/able menu
   public void disable(byte i) {
      boolean d = false;
      switch (i) {
      case 1: {
         // Dal menu principale alla lista tracciati
         d = true;
         principalMDisable(d);
         trackMDisable(d);
      }
      case 2: {
         // Dalla lista tracciati al menu principale
         trackMDisable(d);
         principalMDisable(d);
      }
      }
   }

   public void principalMDisable(Boolean b) {
      if (b == true) {
         // se vero disable il menu principale
         testata.setVisible(false);
         nuova.setVisible(false);
      } else {
         // se falso able il menu principale
         testata.setVisible(true);
         nuova.setVisible(true);
      }
   }

   public void trackMDisable(Boolean b) {
      if (b == true) {
         // se vero able la lista dei tracciati
         selectrack.setVisible(true);
         track1.setVisible(true);
         track2.setVisible(true);
         track3.setVisible(true);
         track4.setVisible(true);
         track5.setVisible(true);
         track6.setVisible(true);
         track7.setVisible(true);
         track8.setVisible(true);
         track9.setVisible(true);
         track10.setVisible(true);
         behind.setVisible(true);
      } else {
         // se falso disable la lista dei tracciati
         selectrack.setVisible(false);
         track1.setVisible(false);
         track2.setVisible(false);
         track3.setVisible(false);
         track4.setVisible(false);
         track5.setVisible(false);
         track6.setVisible(false);
         track7.setVisible(false);
         track8.setVisible(false);
         track9.setVisible(false);
         track10.setVisible(false);
         behind.setVisible(false);
      }
   }

   // Variables declaration - do not modify
   private javax.swing.JLayeredPane background;
   private javax.swing.JLabel behind;
   private javax.swing.JLabel nuova;
   private javax.swing.JLabel selectrack;
   private javax.swing.JLabel testata;
   private javax.swing.JLabel traccy;
   private javax.swing.JLabel track1;
   private javax.swing.JLabel track10;
   private javax.swing.JLabel track2;
   private javax.swing.JLabel track3;
   private javax.swing.JLabel track4;
   private javax.swing.JLabel track5;
   private javax.swing.JLabel track6;
   private javax.swing.JLabel track7;
   private javax.swing.JLabel track8;
   private javax.swing.JLabel track9;
   // End of variables declaration}
}

i don’t receive any compiler error, i think the error is in the Gui class where i add the images, in the metod track1MouseClicked, i use the JFrom plugin of NetBeans 7.01 for create the frame and company.

  • 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-05-26T15:54:51+00:00Added an answer on May 26, 2026 at 3:54 pm

    I haven’t gone through all of your code, but this will cause problems:

    public final Image load(String path, int n, int i) {
      Toolkit tool = Toolkit.getDefaultToolkit();
      String dot = ".jpg";
    
      path = this.path; // *****
    

    Since you don’t really set the path field here. You’ll want to reverse that line.

    More importantly, you’ll want to try to solve your problem in a much smaller simpler program first, a test program that does nothing but read in a bunch of images and displays them, but does nothing else. Then once you have that solved use the code in your larger program. The other benefit is that if your smaller program doesn’t work, you can then post it here as a more reasonably sized program that more folks will be willing to read, analyze, test and correct.

    Also, don’t mix AWT components such as Component with Swing components unless absolutely necessary — which isn’t the case with your program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this class to crop, resize my image: http://www.phpclasses.org/package/4268-PHP-Resize-crop-rotate-flip-flop-and-grey-images.html It uses GD. The
In PHP 4, if you use a class before it's defined you get this
I want to use Coffeescript to create an UIObject class. This class should inherit
I use redirect() (from uri helper) in every function who need to load the
I have a abstract class User and 3 classes who extend from this class
This class hangs at Future.get() method after executing ExecutorService.shutdownNow() called. I don't know what
This class extends Thread and once it is created, the thread is started. This
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there
Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
Given this class public partial class Default : Page { private IRepository repo; ...

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.