好的,所以我制作了一个测试 java 小程序以确保我知道如何制作它们,但我的默认外观和感觉看起来真的很难看。所以我想切换它 Nimbus 但我的默契不起作用。我已经完成了大约一个小时的谷歌搜索,但没有任何结果,除了一个有问题的论坛,但没有我能理解的答案。有任何想法吗?如果这很难理解,我很抱歉。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class Websitetest extends JApplet implements ActionListener, Runnable {
boolean i = false;
Color red = new Color(255, 0, 0);
Color lightgrey = new Color(200, 200, 200);
Thread runner;
public void init() {
setLookAndFeel();
Button dp = new Button("Don't press");
dp.addActionListener(this);
FlowLayout flow = new FlowLayout();
setLayout(flow);
add(dp);
}
public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D) screen;
if (i == false) {screen2D.setColor(lightgrey);}
else {screen2D.setColor(red);}
screen2D.fillRect(0, 0, getSize().width, getSize().height);
screen2D.setColor(Color.black);
if (i == false) {screen2D.drawString("", 5, 60);}
else {screen2D.drawString("I SAID DON'T PRESS!", 90, 60);}
}
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
if (runner != null) {
runner = null;
}
}
public void run() {
Thread thisThread = Thread.currentThread();
}
public void actionPerformed(ActionEvent event) {
i = true;
repaint();
}
private void setLookAndFeel() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception exc) {
//ignore error
}
}
}