简体   繁体   English

Eclipse不会运行我的代码,编辑器根本不会显示任何代码错误

[英]Eclipse will not run my code and the editor shows no code errors at all

The code was running just fine until i tried to re-position a JLabel and although it shows no errors in my code it refuses to run it and gives me the following error... I am trying to move the label to the upper left corner of the JFrame window and the method i used to do so should be perfectly fine. 代码运行得很好,直到我试图重新定位一个JLabel,虽然它在我的代码中没有显示错误但它拒绝运行它并给我以下错误...我试图将标签移动到左上角JFrame窗口和我以前使用的方法应该是完全正常的。 At least to my knowledge. 至少据我所知。 [Beginner Java Dev] [初学者Java Dev]

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: verticalAlignment
at javax.swing.JLabel.checkVerticalKey(JLabel.java:627)
at javax.swing.JLabel.setVerticalAlignment(JLabel.java:713)
at io.Arimore.Launcher.createAndShowGUI(Launcher.java:27)
at io.Arimore.Launcher.access$0(Launcher.java:13)
at io.Arimore.Launcher$1.run(Launcher.java:46)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Code: 码:

package io.Arimore;
import java.awt.*;
import javax.swing.*;

/* FrameDemo.java requires no other files. */
public class Launcher {

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.
 */
private static void createAndShowGUI() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize(); //Gets the user screen size
    int scrnHigh = d.height; //Pulls out the High
    int scrnWide = d.width; //Pulls out the Wide
    //Create and set up the window.
    JFrame frame = new JFrame("Welcome to Arimore.io");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel emptyLabel = new JLabel("Arimore.io - v0.01A");
    emptyLabel.setPreferredSize(new Dimension(175, 100));
    int quatrainsY = (d.height / 2);
    int elabelH = (0 - quatrainsY);
    int elabelW = (0 - (d.width / 2));
    emptyLabel.setVerticalAlignment(elabelH);
    emptyLabel.setHorizontalAlignment(elabelW);
    frame.getContentPane().add(emptyLabel);

    //Display the window.
    frame.pack();

    //setSize(scrnWide *9/10, scrnHigh *9/10);//sets screen to 0.9 size
    frame.setSize(scrnWide, scrnHigh);//sets screen to FULL size
    //setLocation(scrnWide *1/20, scrnHigh *1/20);//CENTER it for 9/10th size
    frame.setLocation(0, 0);//
    frame.setVisible(true);
}

public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}
}

JLabel.setVerticalAlignment takes an int, but the int values should be JLabel.TOP, JLabel.MIDDLE, or JLabel.BOTTOM. JLabel.setVerticalAlignment采用int,但int值应为JLabel.TOP,JLabel.MIDDLE或JLabel.BOTTOM。

Also, JLabel.setHorizontalAlignment will take JLabel.LEFT, JLabel.CENTER, and JLabel.RIGHT. 此外,JLabel.setHorizo​​ntalAlignment将采用JLabel.LEFT,JLabel.CENTER和JLabel.RIGHT。

Any other values will cause an illegal argument exception. 任何其他值都将导致非法参数异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM