谁帮我看下这个就java
packagetext;importjavax.swing.*;importjava.awt.*;publicclassLdextendsJFrame{publicLd(...
package text;import javax.swing.*;
import java.awt.*;public class Ld extends JFrame {
public Ld(){ this.setSize(300,220); this.setLayout(new BorderLayout()); this.setVisible(true); Container con=this.getContentPane(); JPanel titlePanel = new JPanel(); con.add(titlePanel,"North"); con.add(titlePanel); titlePanel.setFont(new Font("",Font.PLAIN,28)); JLabel b=new JLabel("用户名:"); b.setBounds(50, 20, 50, 20); JLabel c=new JLabel("密码:"); c.setBounds(50, 60, 50, 20); JPasswordField e=new JPasswordField(20); e.setBounds(110,20,120,20); JPasswordField txtPwd=new JPasswordField(20); txtPwd.setBounds(110,60,120,20); JPanel as = new JPanel(); JButton f=new JButton("登录"); as.add(f); JButton g=new JButton("关闭"); as.add(g); JPanel fieldPanel = new JPanel(); fieldPanel.setLayout(null); fieldPanel.add(b); fieldPanel.add(c); con.add(as,"South"); con.add(b); con.add(c); con.add(e); con.add(txtPwd); con.add(fieldPanel,"Center"); this.setVisible(true); } public static void main(String[] args) { new Ld();
}} 这些代码要怎么改才能成图片那样 展开
import java.awt.*;public class Ld extends JFrame {
public Ld(){ this.setSize(300,220); this.setLayout(new BorderLayout()); this.setVisible(true); Container con=this.getContentPane(); JPanel titlePanel = new JPanel(); con.add(titlePanel,"North"); con.add(titlePanel); titlePanel.setFont(new Font("",Font.PLAIN,28)); JLabel b=new JLabel("用户名:"); b.setBounds(50, 20, 50, 20); JLabel c=new JLabel("密码:"); c.setBounds(50, 60, 50, 20); JPasswordField e=new JPasswordField(20); e.setBounds(110,20,120,20); JPasswordField txtPwd=new JPasswordField(20); txtPwd.setBounds(110,60,120,20); JPanel as = new JPanel(); JButton f=new JButton("登录"); as.add(f); JButton g=new JButton("关闭"); as.add(g); JPanel fieldPanel = new JPanel(); fieldPanel.setLayout(null); fieldPanel.add(b); fieldPanel.add(c); con.add(as,"South"); con.add(b); con.add(c); con.add(e); con.add(txtPwd); con.add(fieldPanel,"Center"); this.setVisible(true); } public static void main(String[] args) { new Ld();
}} 这些代码要怎么改才能成图片那样 展开
2个回答
展开全部
修改后的代码:
import javax.swing.*;
import java.awt.*;
public class Ld extends JFrame {
public Ld() {
this.setSize(300,220);
this.setLayout(new BorderLayout());
Container con=this.getContentPane();
JPanel titlePanel = new JPanel();
con.add(titlePanel);
JLabel a=new JLabel("登录");
a.setFont(new Font("", Font.PLAIN,28));
titlePanel.add(a);
con.add(titlePanel,"North");
JLabel b=new JLabel("用户名:");
b.setBounds(50, 20, 50, 20);
JLabel c=new JLabel("密 码:");
c.setBounds(50, 50, 50, 20);
JTextField e=new JTextField(20);
e.setBounds(110, 20, 120, 20);
JPasswordField txtPwd=new JPasswordField(20);
txtPwd.setBounds(110, 50, 120, 20);
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
fieldPanel.add(b);
fieldPanel.add(c);
fieldPanel.add(e);
fieldPanel.add(txtPwd);
con.add(fieldPanel, "Center");
JPanel as = new JPanel();
JButton f=new JButton("登录");
as.add(f);
JButton g=new JButton("关闭");
as.add(g);
con.add(as, "South");
this.setVisible(true);
}
public static void main(String[] args) {
new Ld();
}
}
运行效果:
更多追问追答
追问
为什么我运行有错误?代码有没有错?出现这个
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to lay
out: unknown constraint: North搜索
追答
代码有没有提示错误?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询