java程序将Button改成JButton,该如何改?
(出现Accessrestriction:Thetype'JButton'isnotAPI(restrictiononrequiredlibrary'C:\Program...
(出现Access restriction: The type 'JButton' is not API (restriction on required library 'C:\Program Files\Java\jre1.8.0_60\lib\rt.jar')
import java.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class student extends Frame {
public student(){
setTitle("登陆界面");
Panel p1 =new Panel();
Panel p2 =new Panel();
Button j =new Button("登陆");
Label l1 =new Label("用户名");
Label l2 =new Label("密码");
TextField t1 =new TextField(10);
TextField t2 =new TextField(10);
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
add(p1);
add(p2);
add(j);
setLayout(new GridLayout(3,1,3,3));
setVisible(true);
setBounds(300,200,300,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
}
});
}
public static void main(String args[]){
new student();
}
} 展开
import java.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class student extends Frame {
public student(){
setTitle("登陆界面");
Panel p1 =new Panel();
Panel p2 =new Panel();
Button j =new Button("登陆");
Label l1 =new Label("用户名");
Label l2 =new Label("密码");
TextField t1 =new TextField(10);
TextField t2 =new TextField(10);
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
add(p1);
add(p2);
add(j);
setLayout(new GridLayout(3,1,3,3));
setVisible(true);
setBounds(300,200,300,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
}
});
}
public static void main(String args[]){
new student();
}
} 展开
1个回答
展开全部
可以直接替换
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Student extends JFrame {
public Student(){
super("登陆界面");
JPanel p1 =new JPanel();
JPanel p2 =new JPanel();
JButton j =new JButton("登陆");
JLabel l1 =new JLabel("用户名");
JLabel l2 =new JLabel("密码");
JTextField t1 =new JTextField(10);
JTextField t2 =new JTextField(10);
p1.add(l1);
p1.add(t1);
p2.add(l2);
p2.add(t2);
setLayout(new GridLayout(3,1,3,3));
add(p1);
add(p2);
add(j);
setBounds(300,200,300,200);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]){
new Student();
}
}
追问
但是我这里显示这样得错误:Access restriction: The type 'JButton' is not API (restriction on required library 'C:\Program Files\Java\jre1.8.0_60\lib\rt.jar')
到底是什么原因?jdk?
追答
把eclipse里的jre删掉,重新添加一次
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询