📄 猜数.txt
字号:
import javax.swing.*;
public class Caishu {
public static void main(String[] args) {
JFrame frame = new JFrame ("Cai shu");
frame.setDefaultCloseOperation (
JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(
new caishuPanel());
frame.pack();
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class caishuPanel extends JPanel
{
private JLabel inputLabel, outputLabel, resultLabel;
private JTextField fahrenheit;
public FahrenheitPanel()
{
inputLabel = new JLabel (
"Enter Fahrenheit temperature:");
outputLabel = new JLabel (
"Temperature in Celsius: ");
resultLabel = new JLabel ("---");
fahrenheit = new JTextField (5);
fahrenheit.addActionListener (new TempListener());
add (inputLabel);
add (fahrenheit);
add (outputLabel);
add (resultLabel);
setPreferredSize (new Dimension(300, 75));
setBackground (Color.yellow);
}
private class TempListener implements ActionListener{
public void actionPerformed (ActionEvent event)
{
int fahrenheitTemp, celsiusTemp;
String text = fahrenheit.getText();
fahrenheitTemp = Integer.parseInt (text);
if celsiusTemp = (fahrenheitTemp-32) * 5/9;
resultLabel.setText (
Integer.toString (celsiusTemp));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -