I am doing a simple project in java swing, just to make time pass. When I try to start the application, it gives me this error:
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Java\bin\awt.dll: Routine di inizializzazione della libreria di collegamento dinamico (DLL) non riuscita
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:310)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:280)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2416)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:809)
at java.base/java.lang.System.loadLibrary(System.java:1893)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1380)
at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:1378)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at java.desktop/java.awt.Toolkit.loadLibraries(Toolkit.java:1377)
at java.desktop/java.awt.Toolkit.<clinit>(Toolkit.java:1410)
at java.desktop/java.awt.Component.<clinit>(Component.java:622)
at com.company.Main.main(Main.java:6)
Here's the code (I got 3 classes):
this is the class page:
package com.company;
import javax.swing.*;
import java.awt.*;
public class Page extends JFrame {
Header header = new Header();
public Page(){
super("FW Ultra");
this.setSize(1000, 700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(new FlowLayout());
this.add(header);
this.setVisible(true);
}
}
this is the class header:
package com.company;
import javax.swing.*;
import java.awt.*;
public class Header extends JPanel {
public Header(){
super();
this.setLayout(new BorderLayout());
add(new JLabel("FVU | Film Viewer Ultra"), BorderLayout.WEST);
add(new JLabel("Version 1.0"), BorderLayout.EAST);
}
}
and this is the main
package com.company;
public class Main {
public static void main(String[] args) {
Page p = new Page();
}
}
PLZ help mee
I made a couple of changes to your code and came up with this GUI. I reduced the size of the GUI by half so it would fit better in the answer.
I changed some of the code in all three of your classes. I made your classes inner classes so I could post them as one block. You should separate them.
I started your Swing GUI with a call to the SwingUtilities
invokeLater
method. This method ensures that the Swing components are created and executed on the Event Dispatch Thread .
Here's the complete runnable code.
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class FileViewerMain {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new FileViewerMain().new Page();
}
});
}
public class Page extends JFrame {
Header header = new Header();
public Page(){
super("FW Ultra");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(new Header(), BorderLayout.BEFORE_FIRST_LINE);
this.setSize(500, 350);
this.setVisible(true);
}
}
public class Header extends JPanel {
public Header(){
super();
this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.setLayout(new BorderLayout());
add(new JLabel("FVU | Film Viewer Ultra"), BorderLayout.WEST);
add(new JLabel("Version 1.0"), BorderLayout.EAST);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.