📄 oracle.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Oracle extends JApplet implements ActionListener
{
public static int LINES = 5;
public static int CHAR_PER_LINE = 40;
private JTextArea theText;
private String question;
private String answer;
private String advice;
public void init()
{
Container contentPane = getContentPane( );
contentPane.setLayout(new FlowLayout( ));
contentPane.setBackground( Color.GREEN );
JLabel instructions =
new JLabel("I will answer any question, " +
"but may need some advice from you.");
contentPane.add(instructions);
JButton getAnswerButton = new JButton("Get Answer");
getAnswerButton.addActionListener(this);
contentPane.add(getAnswerButton);
JButton sendAdviceButton = new JButton("Send Advice");
sendAdviceButton.addActionListener(this);
contentPane.add(sendAdviceButton);
JButton resetButton = new JButton("Reset");
resetButton.addActionListener(this);
contentPane.add(resetButton);
theText = new JTextArea(LINES, CHAR_PER_LINE);
theText.setText("Questions and advice go here.");
contentPane.add(theText);
//answer = "The answer is: Look around."; //for first answer
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand( );
if (actionCommand.equals("Get Answer"))
{
question = theText.getText();
theText.setText("That is a difficult question.\n" +
"I need some advice.\n" +
"Give me some advice and click button.");
}
else if(actionCommand.equals("Send Advice"))
{
advice = theText.getText();
answer = "The answer is: " + advice;
theText.setText("That advice helped.\n" +
"You asked the question: " + question
+ "\n" + answer +
"\nClick the Reset button and" +
"\nLeave the program on for others.");
//answer = "The answer is: " + advice;
}
else if(actionCommand.equals("Reset"))
{
theText.setText("Questions and advice go here.");
}
else
theText.setText("Error");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -