Note that there are some explanatory texts on larger screens.

plurals
  1. POGet applet to load pictures when user clicks on Level one
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8325389/adding-image-in-japplet">Adding image in JApplet</a> </p> </blockquote> <p>I have my program compiled into one class file for an applet and it runs and works through java but when i added it into my html web page it will not load the pictures, i have all the pictures and the class and html page in one file and it loads the applet and i can click level one it just won't paint the pictures. Here is my code.</p> <pre><code> import javax.swing.JApplet; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JPanel; public class MainApplet extends JApplet { public void init() { LabelFrame frame = new LabelFrame(); } public class LabelFrame { public LabelFrame( ) { int x = 500; // final LoadingPictures panel=new LoadingPictures(); setSize(x,500); setLocation(350,200); setVisible(true); JMenuBar menubar = new JMenuBar(); setJMenuBar(menubar); JMenu Change = new JMenu("Pick a Level"); menubar.add(Change); JMenu Move = new JMenu("Move keys"); menubar.add(Move); JMenu Options = new JMenu("Options"); menubar.add(Options); JMenu About = new JMenu("About"); menubar.add(About); JMenu Select = new JMenu("Select"); menubar.add(Select); final JMenuItem black = new JMenuItem("Black BackGround"); Options.add(black); final JMenuItem blue = new JMenuItem("Blue BackGround"); Options.add(blue); final JMenuItem yellow = new JMenuItem("Yellow BackGround"); Options.add(yellow); final JMenuItem green = new JMenuItem("Green BackGround"); Options.add(green); final JMenuItem white = new JMenuItem("White BackGround"); Options.add(white); JMenuItem info = new JMenuItem("infomation"); About.add(info); JMenuItem Level2 = new JMenuItem("Level 1"); Change.add(Level2); final JRadioButton redBlock = new JRadioButton("redblock"); final JButton moveleft = new JButton("Left"); final JButton moveright = new JButton("Right"); Select.add(redBlock); Move.add(moveleft); Move.add(moveright); Level2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event1) { final LoadingPictures levelpics1 = new LoadingPictures(1); add(levelpics1); //levelpics1.setVisible(false); //levelpics1.setVisible(true); revalidate(); //repaint(); //Move the redblock right redBlock.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent rightselect) { moveright.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent right) { if (LoadingPictures.topone ==400) { JOptionPane.showMessageDialog(null, "You have won the level now move to next level"); } else {LoadingPictures.topone+= 50; levelpics1.repaint();} }}); }}); //Move the redblock left redBlock.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent leftselect) { moveleft.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent left) { if (LoadingPictures.topone == 0) { JOptionPane.showMessageDialog(null, "Can not move left anymore"); } else { LoadingPictures.topone-= 50; levelpics1.repaint(); } }}); }}); int delay3 = 500; //milliseconds ActionListener taskPerformer3 = new ActionListener() { public void actionPerformed(ActionEvent evt) { if(LoadingPictures.level2topleft == 0) { LoadingPictures.level2topleft+=325; levelpics1.repaint(); } else { LoadingPictures.level2topleft-=25; levelpics1.repaint(); } } }; new Timer(delay3, taskPerformer3).start(); int delay2 = 1000; //milliseconds ActionListener taskPerformer2 = new ActionListener() { public void actionPerformed(ActionEvent evt) { if(LoadingPictures.topleftone == 0) { LoadingPictures.topleftone+=325; levelpics1.repaint(); } else { LoadingPictures.topleftone-=25; levelpics1.repaint(); } } }; new Timer(delay2, taskPerformer2).start(); int delay11 = 750; //milliseconds ActionListener taskPerformer11 = new ActionListener() { public void actionPerformed(ActionEvent evt) { if(LoadingPictures.level2topfor4block == 300) { LoadingPictures.level2topfor4block-=300; levelpics1.repaint(); } else { LoadingPictures.level2topfor4block+=25; levelpics1.repaint(); } } }; new Timer(delay11, taskPerformer11).start(); black.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { levelpics1.setBackground(Color.black); }}); blue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { levelpics1.setBackground(Color.blue); }}); yellow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { levelpics1.setBackground(Color.yellow); }}); green.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { levelpics1.setBackground(Color.green); }}); white.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { levelpics1.setBackground(Color.white); }}); } }); info.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null,"•This is our Final project for computer programming 3 \n" + "•\n•Based off of the " + "game by KIRA GAmes called UnBlock Me"); }}); } } public static class LoadingPictures extends JPanel{ ImageIcon block2vertical = new ImageIcon ("2block.jpg"); ImageIcon block4vertical = new ImageIcon("4block.jpg"); ImageIcon redblock = new ImageIcon("redblockhorizontal.jpg"); ImageIcon Level2block4 = new ImageIcon("Level2block4.jpg"); ImageIcon Level2block2 = new ImageIcon("Level2block2.jpg"); static int top = 0; static int topone = 0; static int topleft = 200; static int level2topleft = 200; static int topleftone = 225; static int topfor4blockvertical = 150; static int level2topfor4block = 150; private int j; public LoadingPictures(int i) { super(); j = i; } public void paintComponent(Graphics g) { super.paintComponent(g); if (j == 1) { g.drawImage(redblock.getImage(),topone,200,this); g.drawImage(Level2block4.getImage(),350,level2topfor4block,this); g.drawImage(Level2block2.getImage(),100,level2topleft,this); g.drawImage(Level2block2.getImage(),200,topleftone,this); } else if(j == 2) { } } } } </code></pre> <p>and this is the line of code i have in my html that loads the applet</p> <pre><code> &lt;applet code ="MainApplet.class" height = "500" width = "500"&gt;&lt;/applet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload