不知道使用JLayeredPane时在何处形成编译器错误 [英] No idea where compiler errors are forming when using JLayeredPane

查看:102
本文介绍了不知道使用JLayeredPane时在何处形成编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我的最后一个问题中(无法弄清楚如何在Java中重叠图像"),建议我使用布局管理器和JLayeredPane.但是,在研究了演示并形成了自己的代码之后,我遇到了多达34个编译器错误.编译器错误始终为",因此导入可能存在问题.但是,我完全从LayeredPane演示中复制了导入列表.再一次,我很沮丧.我还要再次感谢任何人的建议!

So, in my last question ("Can't figure out how to overlap images in java") I was kindly advised to utilize layout managers and the JLayeredPane. However, after studying the demos, and forming my own code, I have a whopping 34 compiler errors. The compiler errors are consistently "" so there's probably something wrong with importing. However I copied the import list exactly from the LayeredPane Demo. Once again, I am stumped. And also once again, I thank anyone in advance for advice!

import javax.swing.*;
import javax.swing.border.*;
import javax.accessibility.*;

import java.awt.*;
import java.awt.event.*;


public class SlotAnimatorTest extends JPanel
{
  JPanel pane = new JPanel ();
  pane.setPreferredSize(new Dimension(1500, 1500));
  JPanel slotAnim;

  private JPanel showSlotAnimators ()
  {
    slotAnim = new JPanel ();

    SlotAnimator a0 = new SlotAnimator (45);
    SlotAnimator a1 = new SlotAnimator (90);
    SlotAnimator a2 = new SlotAnimator (180);

    slotAnim.setLayout (new GridLayout (3,0,20,30));
    slotAnim.add (a0);
    slotAnim.add (a1);
    slotAnim.add (a2);

    return slotAnim;
  }

  ImageIcon background = new ImageIcon ("/Users/haleywight/Documents/slotmachine.png");
  JLabel bG = new JLabel (background);
  bGsetBounds(1500, 760, background.getIconWidth(), background.getIconHeight());
  pane.add (bG, newInteger(0),0);

  pane.add (showSlotAnimators (), newInteger (1));

      private static void createAndShowGUI() 
      {

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JComponent newContentPane = new SlotAnimatorTest();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
     }

  public static void main (String [] args)
    {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}

推荐答案

这与JLayeredPane无关,与基本Java无关.您不能在类中以及方法,构造函数或静态/非静态初始化程序块之外调用方法.

This has nothing to do with JLayeredPane and much to do with basic Java. You can't call a method in the class and outside of a method or constructor or static/non-static initializer blocks.

这篇关于不知道使用JLayeredPane时在何处形成编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆