JAVA小白求回答~急~ 我想通过在我做的窗口中的文本框内输入不同的数字,点确定按钮之后,弹出不同的窗口 10
出现了bug不知道怎么解决代码在这里:importjava.awt.BorderLayout;importjava.awt.FlowLayout;importjava.a...
出现了bug不知道怎么解决
代码在这里:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javafx.event.ActionEvent;
public class RobotInterface {
private JFrame frame1 = new JFrame("come on");
private JLabel tit = new JLabel("Please select an option:") ;
private JPanel pan1 = new JPanel();
private JPanel pan2 = new JPanel();
public RobotInterface(){
Font fon2 = new Font("Comic",Font.BOLD,30);
frame1.setLayout(new BorderLayout(3,3));
tit.setFont(fon2);
pan1.setLayout(new GridLayout(2,3,3,3));
JButton lab1 = new JButton("1. Fish ");
JButton lab2 = new JButton("2. Meat ");
JButton lab3 = new JButton("3. Rice ");
JButton lab4 = new JButton("4. Noodle");
JButton lab5 = new JButton("5. Drink ");
Font fon1 = new Font("Comic",Font.BOLD,38);
lab1.setFont(fon1);
lab2.setFont(fon1);
lab3.setFont(fon1);
lab4.setFont(fon1);
lab5.setFont(fon1);
pan1.add(lab1);
pan1.add(lab2);
pan1.add(lab3);
pan1.add(lab4);
pan1.add(lab5);
pan2.setLayout(new FlowLayout(FlowLayout.RIGHT,3,3));
JTextField select = new JTextField(30);
JLabel tex = new JLabel("Option selected:");
JButton sub = new JButton("OK");
tex.setFont(fon2);
sub.setFont(fon2);
pan2.add(tex);
pan2.add(select);
pan2.add(sub);
sub.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0){
if (arg0.getSource()== sub){
String tnum = select.getText();
int num = Integer.parseInt(tnum);
if (num == 1){
new FishMenu();
}
else{
System.out.println("otherwise");
}
}
}
});
frame1.add(tit,BorderLayout.NORTH);
frame1.add(pan1,BorderLayout.CENTER);
frame1.add(pan2,BorderLayout.SOUTH);
frame1.setVisible(true);
}
}
56行:
The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
57行:
The method actionPerformed(ActionEvent) from the type new ActionListener(){} is never used locally 展开
代码在这里:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javafx.event.ActionEvent;
public class RobotInterface {
private JFrame frame1 = new JFrame("come on");
private JLabel tit = new JLabel("Please select an option:") ;
private JPanel pan1 = new JPanel();
private JPanel pan2 = new JPanel();
public RobotInterface(){
Font fon2 = new Font("Comic",Font.BOLD,30);
frame1.setLayout(new BorderLayout(3,3));
tit.setFont(fon2);
pan1.setLayout(new GridLayout(2,3,3,3));
JButton lab1 = new JButton("1. Fish ");
JButton lab2 = new JButton("2. Meat ");
JButton lab3 = new JButton("3. Rice ");
JButton lab4 = new JButton("4. Noodle");
JButton lab5 = new JButton("5. Drink ");
Font fon1 = new Font("Comic",Font.BOLD,38);
lab1.setFont(fon1);
lab2.setFont(fon1);
lab3.setFont(fon1);
lab4.setFont(fon1);
lab5.setFont(fon1);
pan1.add(lab1);
pan1.add(lab2);
pan1.add(lab3);
pan1.add(lab4);
pan1.add(lab5);
pan2.setLayout(new FlowLayout(FlowLayout.RIGHT,3,3));
JTextField select = new JTextField(30);
JLabel tex = new JLabel("Option selected:");
JButton sub = new JButton("OK");
tex.setFont(fon2);
sub.setFont(fon2);
pan2.add(tex);
pan2.add(select);
pan2.add(sub);
sub.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0){
if (arg0.getSource()== sub){
String tnum = select.getText();
int num = Integer.parseInt(tnum);
if (num == 1){
new FishMenu();
}
else{
System.out.println("otherwise");
}
}
}
});
frame1.add(tit,BorderLayout.NORTH);
frame1.add(pan1,BorderLayout.CENTER);
frame1.add(pan2,BorderLayout.SOUTH);
frame1.setVisible(true);
}
}
56行:
The type new ActionListener(){} must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
57行:
The method actionPerformed(ActionEvent) from the type new ActionListener(){} is never used locally 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询