除按钮之外的所有东西都显示在窗口中。有我失踪的东西吗? 这是第一次使用按钮,我不知道发生了什么问题。这可能是一个格式问题。 有人可以告诉我,如果setLocation()和setSize()有问题吗?按钮没有出现在我的Jframe中
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.TextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class HashString extends JPanel {
public static void hashString() {
}
public void window() {
JLabel label1 = new JLabel(
"Enter Your Strings separated by a comma, below. ");
label1.setHorizontalAlignment(JLabel.CENTER);
label1.setFont(new Font("Times New Roman", Font.BOLD, 12));
label1.setVerticalAlignment(JLabel.TOP);
JTextField field = new JTextField(50);
field.setVisible(true);
field.setText("Enter Strings Here");
field.setSize(300, 251);
field.setHorizontalAlignment(JTextField.CENTER);
field.setLocation(135, 60);
Button btn = new Button("Enter These Values");
btn.setLocation(240 ,420);
btn.setSize(100, 100);
btn.setVisible(true);
btn.setFont(new Font("Times new roman",Font.BOLD,12));
JFrame frame = new JFrame("Test1");
frame.add(new HashString());
frame.add(btn);
frame.setVisible(true);
frame.add(field);
frame.setLocationRelativeTo(null);
frame.add(label1);
frame.setSize(600, 450);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
这是,shoudlve在最后添加了setVisible。 –