Java边框布局问题?
这是我的程序。我希望按钮位于框架的北侧,但是当我尝试使用边框布局时,会出现在该行定义的错误。
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.*;
public class testt {
static JFrame jj=new JFrame("Test frame");
public static void main (String[] args){
jj.setBounds(100, 200, 400, 300);
jj.setVisible(true);
jj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jj.add(new JButton("North",BorderLayout.NORTH)); //The constructor JButton(String, String) is undefined
}
}
This is my program.I want to have the button on north side of the frame but when i try to use the border layout gives an error defined at that line.
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.*;
public class testt {
static JFrame jj=new JFrame("Test frame");
public static void main (String[] args){
jj.setBounds(100, 200, 400, 300);
jj.setVisible(true);
jj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jj.add(new JButton("North",BorderLayout.NORTH)); //The constructor JButton(String, String) is undefined
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您将 BorderLayout 约束作为构造函数的参数,它应该是
add()
的参数,如上所述。You had the BorderLayout constraint as a parameter to the constructor, it should be a parameter to
add()
as above.您应该将:
...更改为:
You should change:
... to:
你只是破旧地使用
像这样修改你的代码
you just worngly use
revise your code like
这是更正后的代码。尝试一下并观察哪里出了问题。如有任何疑问,请随时询问,
导入 java.awt.BorderLayout;
导入java.awt.Component;
导入 javax.swing.*;
公开课测试{
}
Here is the corrected code. Try this and observe what was wrong. In case of any query, feel free to ask,
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.*;
public class testt {
}