import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class logintest extends JFrame
{
private JLabel userNameLabel;
private JLabel passwordLabel;
private JButton login;
private JButton cancel;
public static void main(String[] args)
{
new logintest();
}
public logintest ()
{
setTitle("登录进销存管理系统");
loginPanel loginPanel = new loginPanel();
loginPanel.setLayout(null);
loginPanel.setBounds(450,200,loginPanel.getWidth(), loginPanel.getHeight());
getContentPane().add(loginPanel);
userNameLabel = new JLabel();
userNameLabel.setText("用户名");
userNameLabel.setBounds(100,135,200,25);
loginPanel.add(userNameLabel);
passwordLabel = new JLabel();
passwordLabel.setText("密码");
passwordLabel.setBounds(100,165,200,25);
loginPanel.add(passwordLabel);
login = new JButton();
login.setText("登录");
login.setBounds(180, 195, 60, 25);
loginPanel.add(login);
cancel = new JButton();
cancel.setText("取消");
cancel.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
System.exit(0);
}
});
cancel.setBounds(260, 195, 60, 25);
loginPanel.add(cancel);
setVisible(true);
setResizable(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public class loginPanel extends JPanel
{
public ImageIcon icon;
public int width, height;
public loginPanel()
{
super();
icon = new ImageIcon("res/login.jpg");
width = icon.getIconWidth();
height = icon.getIconHeight();
setSize(width, height);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Image img = icon.getImage();
g.drawImage(img, 0, 0, getParent());
}
}
}
运行以下Java程序,窗口只有一小块,需要拖动窗口才能显示出组件。
答案:1 悬赏:0 手机版
解决时间 2021-01-25 11:13
- 提问者网友:箛茗
- 2021-01-24 22:46
最佳答案
- 五星知识达人网友:等灯
- 2021-01-24 23:38
在public logintest ()这个方法中加入如下语句即可
this.setBounds(200, 100, 300, 200); //置窗体位置及大小
this.setBounds(200, 100, 300, 200); //置窗体位置及大小
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯