这段代码为什么Eclipse没有报错,但是文件上面始终有个红叉叉
importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;i...
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
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;
public class Three {
public static void main(String[] args){
IFrame frame =new IFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}}
class IFrame extends JFrame{
public static final int width = 250;
public static final int height =250;
public IFrame(){
setTitle("Welcome");
setSize(width,height);
IPanels panel =new IPanels();
Container ContentPane=getContentPane();
ContentPane.add(panel);
}}
class IPanels extends JPanel{
public IPanels(){
setLayout( new FlowLayout(FlowLayout.LEFT));
JLabel la1 =new JLabel("输入整数a:");
JLabel la2 = new JLabel("输入整数b:");
JButton btn =new JButton("比较");
final JTextField num1 =new JTextField(10);
final JTextField num2 =new JTextField(10);
final JLabel res =new JLabel("结果");
add(la1);
add(num1);
add(la2);
add(num2);
add(btn);
add(res);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = num1.getText();
String s2 =num2.getText();
int a =Integer.parseInt(s1);
int b =Integer.parseInt(s2);
String str =new String();
if(a>b)
str = "a>b";
else if(a==b)
str ="a=b";
else
str = "a<b";
res.setText("结果:"+str);
} });} 展开
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
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;
public class Three {
public static void main(String[] args){
IFrame frame =new IFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}}
class IFrame extends JFrame{
public static final int width = 250;
public static final int height =250;
public IFrame(){
setTitle("Welcome");
setSize(width,height);
IPanels panel =new IPanels();
Container ContentPane=getContentPane();
ContentPane.add(panel);
}}
class IPanels extends JPanel{
public IPanels(){
setLayout( new FlowLayout(FlowLayout.LEFT));
JLabel la1 =new JLabel("输入整数a:");
JLabel la2 = new JLabel("输入整数b:");
JButton btn =new JButton("比较");
final JTextField num1 =new JTextField(10);
final JTextField num2 =new JTextField(10);
final JLabel res =new JLabel("结果");
add(la1);
add(num1);
add(la2);
add(num2);
add(btn);
add(res);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = num1.getText();
String s2 =num2.getText();
int a =Integer.parseInt(s1);
int b =Integer.parseInt(s2);
String str =new String();
if(a>b)
str = "a>b";
else if(a==b)
str ="a=b";
else
str = "a<b";
res.setText("结果:"+str);
} });} 展开
展开全部
有两个错误,最后的一个分号输入法错误,那是中文分号,另外就是最后还差一个大括号。
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
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;
public class Three {
public static void main(String[] args){
IFrame frame =new IFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class IFrame extends JFrame{
public static final int width = 250;
public static final int height =250;
public IFrame(){
setTitle("Welcome");
setSize(width,height);
IPanels panel =new IPanels();
Container ContentPane=getContentPane();
ContentPane.add(panel);
}
}
class IPanels extends JPanel{
public IPanels(){
setLayout( new FlowLayout(FlowLayout.LEFT));
JLabel la1 =new JLabel("输入整数a:");
JLabel la2 = new JLabel("输入整数b:");
JButton btn =new JButton("比较");
final JTextField num1 =new JTextField(10);
final JTextField num2 =new JTextField(10);
final JLabel res =new JLabel("结果");
add(la1);
add(num1);
add(la2);
add(num2);
add(btn);
add(res);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = num1.getText();
String s2 =num2.getText();
int a =Integer.parseInt(s1);
int b =Integer.parseInt(s2);
String str =new String();
if(a>b)
str = "a>b";
else if(a==b)
str ="a=b";
else
str = "a<b";
res.setText("结果:"+str);
}
});
}
}
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
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;
public class Three {
public static void main(String[] args){
IFrame frame =new IFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class IFrame extends JFrame{
public static final int width = 250;
public static final int height =250;
public IFrame(){
setTitle("Welcome");
setSize(width,height);
IPanels panel =new IPanels();
Container ContentPane=getContentPane();
ContentPane.add(panel);
}
}
class IPanels extends JPanel{
public IPanels(){
setLayout( new FlowLayout(FlowLayout.LEFT));
JLabel la1 =new JLabel("输入整数a:");
JLabel la2 = new JLabel("输入整数b:");
JButton btn =new JButton("比较");
final JTextField num1 =new JTextField(10);
final JTextField num2 =new JTextField(10);
final JLabel res =new JLabel("结果");
add(la1);
add(num1);
add(la2);
add(num2);
add(btn);
add(res);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = num1.getText();
String s2 =num2.getText();
int a =Integer.parseInt(s1);
int b =Integer.parseInt(s2);
String str =new String();
if(a>b)
str = "a>b";
else if(a==b)
str ="a=b";
else
str = "a<b";
res.setText("结果:"+str);
}
});
}
}
追问
刚问题确实少了个括号,是我填写问题的时候手误的,原代码有,知道为什么报错了,解决了,还是要谢谢你
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最后的那个分号。。。是手误吗
追问
刚问题确实少了个括号,是我填写问题的时候手误的,原代码有,知道为什么报错了,解决了,还是要谢谢你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
问题在最后一行 少一个括号
} });
}
}
} });
}
}
追问
刚问题确实少了个括号,是我填写问题的时候手误的,原代码有,知道为什么报错了,解决了,还是要谢谢你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询