以下代码来自我的学校作业。做了一个mainFrame类的对象,它假设显示一些文本字段和按钮。 问题是我创建的所有内容都属于同一行,不幸的是,我无法使用java FX。如何让它们落在不同的行?谢谢
public class TempConverter extends MainFrame {
public TempConverter() {
super("Simple Temperature Converter Application", 350,160);
// add(new ConverterPanel());
}
static public void main(String[] args) {
TempConverter tcApp = new TempConverter();
tcApp.display();
}
}
// == mainFrame
/**
* Created by Shirin on 2/4/17.
*/
import javax.swing.*;
import java.awt.*;
public class MainFrame extends JFrame{
JPanel panel = new JPanel();
private JLabel lab;
JButton toCelsius = new JButton("To Celsius");
JButton toFahrenheit = new JButton("To Fahrenheit ");
TextField fahrenheitText = new TextField(), celsiusText = new TextField();
TextField toCelsiusText = new TextField(),toFahrenheitText = new TextField();
public MainFrame(String title, int width, int height) {
super(title);
this.setFrame(width, height);
}
public void display() {
setVisible(true);
}
private void setFrame(int width, int height) {
setSize(width, height);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addComponents();
}
public void addComponents(){
fahrenheitText.setSize(42,42);
fahrenheitText.setLocation(0,0);
toCelsius.setSize(42,42);
toCelsiusText.setLocation(2,2);
toCelsiusText.isEnabled();
celsiusText.setSize(200,100);
celsiusText.isEnabled();
celsiusText.setLocation(6,6);
toFahrenheit.setSize(42,42);
panel.add(fahrenheitText);
panel.add(toCelsius);
panel.add(toCelsiusText);
panel.add(celsiusText);
panel.add(toFahrenheit);
this.add(panel);
}
}