Java 为什么赢了';t我的If语句以线程形式发出
我正在做一个学校的项目,但我的多线程不起作用。主脚本正在运行,工作正常,但在第二个线程中,if语句从未触发。经过几次测试后,while循环正在运行,但是当变量发生变化时,if语句永远不会触发。我尝试过移动一些东西,但是没有成功地使if语句触发。谢谢你能给我的帮助Java 为什么赢了';t我的If语句以线程形式发出,java,Java,我正在做一个学校的项目,但我的多线程不起作用。主脚本正在运行,工作正常,但在第二个线程中,if语句从未触发。经过几次测试后,while循环正在运行,但是当变量发生变化时,if语句永远不会触发。我尝试过移动一些东西,但是没有成功地使if语句触发。谢谢你能给我的帮助 import javax.swing.*; import java.util.ArrayList; public class mainSystem extends JFrame { public static class S
import javax.swing.*;
import java.util.ArrayList;
public class mainSystem extends JFrame {
public static class Stats {
public static int a = 0;
public static int x = 1;
public static int n = 0;
public static ArrayList<String> contacts = new ArrayList<>(n);
public static int karma = 0;
public static int getKarma = 0;
public static int SPC = 0;
public static int getSPC = 0;
public static int OPC = 0;
public static int getOPC = 0;
public static int wisdom = 0;
public static int getWisdom = 0;
public static int billsProposed = 0;
public static int getBillsProposed = 0;
public static int billsPassed = 0;
public static int getBillsPassed = 0;
public static String party;
public static String currentBill;
}
public static JFrame f;
public mainSystem() {
JTable statsWindow;
f = new JFrame();
String[] columns = new String[]{"Stat", "Value"};
Object[][] data = new Object[][]{{"Karma", Stats.karma}, {"SPC", Stats.SPC}, {"OPC", Stats.OPC}, {"Wisdom", Stats.wisdom}, {"Bills Proposed", Stats.billsProposed}, {"Bills Passed", Stats.billsPassed}, {"Party", Stats.party}};
statsWindow = new JTable(data, columns);
f.add(new JScrollPane(statsWindow));
f.setTitle("Stat Window");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
public static void addToContacts(String name){
Stats.n = Stats.n + 1;
Stats.contacts.add(name);
}
public static void table() {
if (Stats.a != 0){
f.dispose();
}
Stats.a += 1;
SwingUtilities.invokeLater(mainSystem::new);
}
public static void main(String[] args) throws InterruptedException {
Thread runSections = new Thread(() -> {
while (Stats.x == 1){
try {
intro.Introduction();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Section1.section1();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
}
if (Stats.x != 1){
End.loose();
} else{
End.win();
}
});
Thread tableUpdater = new Thread(() -> {
while (true) {
if (Stats.getKarma != Stats.karma) {
Stats.getKarma = Stats.karma;
table();
} else if (Stats.getSPC != Stats.SPC){
Stats.getSPC = Stats.SPC;
table();
} else if (Stats.getOPC != Stats.OPC){
Stats.getOPC = Stats.OPC;
table();
} else if (Stats.getWisdom != Stats.wisdom){
Stats.getWisdom = Stats.wisdom;
table();
} else if (Stats.getBillsProposed != Stats.billsProposed){
Stats.getBillsProposed = Stats.billsProposed;
table();
} else if (Stats.getBillsPassed != Stats.billsPassed){
Stats.getBillsPassed = Stats.billsPassed;
table();
}
}
});
tableUpdater.start();
runSections.start();
}
}`
import javax.swing.*;
导入java.util.ArrayList;
公共类main系统扩展JFrame{
公共静态类统计信息{
公共静态int a=0;
公共静态int x=1;
公共静态int n=0;
public static ArrayList contacts=new ArrayList(n);
公共静态因果报应=0;
公共静态int getKarma=0;
公共静态int SPC=0;
公共静态int getSPC=0;
公共静态int OPC=0;
公共静态int getOPC=0;
公共静态智力=0;
公共静态int getWisset=0;
公共静态int billsProposed=0;
公共静态int getBillsProposed=0;
公共静态int billsPassed=0;
公共静态int getBillsPassed=0;
公众静态串党;
公共静态票据;
}
公共静态jf框架;
公共管理系统(){
JTable statsWindow;
f=新的JFrame();
字符串[]列=新字符串[]{“Stat”,“Value”};
对象[][]数据=新对象[][{{“Karma”,Stats.Karma},{“SPC”,Stats.SPC},{“OPC”,Stats.OPC},{“wist”,Stats.wist},{“Bills Proposed”,Stats.billsProposed},{“Bills Passed”,Stats.billsPassed},{“Party”,Stats.Party};
statsWindow=新的JTable(数据、列);
f、 添加(新的JScrollPane(statsWindow));
f、 setTitle(“统计窗口”);
f、 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f、 包装();
f、 setVisible(真);
}
公共静态void addToContacts(字符串名称){
统计n=统计n+1;
Stats.contacts.add(name);
}
公共静态无效表(){
如果(统计数据a!=0){
f、 处置();
}
统计数据a+=1;
调用器(mainSystem::new);
}
公共静态void main(字符串[]args)引发InterruptedException{
线程运行部分=新线程(()->{
而(Stats.x==1){
试一试{
简介(;
}捕捉(中断异常e){
e、 printStackTrace();
}
试一试{
第1节第1节();
}捕捉(中断异常e){
e、 printStackTrace();
}
打破
}
如果(Stats.x!=1){
结束。松开();
}否则{
结束。赢();
}
});
线程表更新程序=新线程(()->{
while(true){
如果(Stats.getKarma!=Stats.karma){
Stats.getKarma=Stats.karma;
表();
}else if(Stats.getSPC!=Stats.SPC){
Stats.getSPC=Stats.SPC;
表();
}else if(Stats.getOPC!=Stats.OPC){
Stats.getOPC=Stats.OPC;
表();
}else if(Stats.getWisdom!=Stats.wisdom){
Stats.getWisdom=Stats.wisdom;
表();
}else if(Stats.getBillsProposed!=Stats.billsProposed){
Stats.getBillsProposed=Stats.billsProposed;
表();
}else if(Stats.getBillsPassed!=Stats.billsPassed){
Stats.getBillsPassed=Stats.billsPassed;
表();
}
}
});
tableUpdater.start();
runSections.start();
}
}`
见:非常感谢