所以我有以下代码:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextPane;
@SuppressWarnings("serial")
public class Window extends JPanel implements ActionListener {
public static JTextPane text = new JTextPane();
public static BorderLayout layout = new BorderLayout();
public static JButton debug = new JButton("Debug");
public static boolean isDebugPressed = false;
public static JFrame frame = new JFrame();
public Window(){
debug.addActionListener(this);
this.setLayout(layout);
this.add(debug,BorderLayout.NORTH);
this.add(text,BorderLayout.CENTER);
}
public static void main(String[] args){
Window window = new Window();
frame.setLayout(layout);
frame.setSize(new Dimension(600,600));
frame.setTitle("QuickScript Compiler");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.add(window);
debug.setActionCommand("debug");
if (isDebugPressed){
JOptionPane.showMessageDialog(frame, "Output: " + text.getText().toString() , "Debugging", JOptionPane.PLAIN_MESSAGE);
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("debug")){
isDebugPressed = true;
System.out.println("true");
}
}
当我按下调试按钮时,应该会弹出一个框并显示我在文本窗格中输入的任何内容,但没有显示任何内容。我该如何解决?我有一种感觉,我可能错过了一些非常重要的东西,但我就是想不通它是什么。感谢任何可以提供帮助的人:D