为了账号安全,请及时绑定邮箱和手机立即绑定

JComponents没有出现有图片背景?

JComponents没有出现有图片背景?

至尊宝的传说 2019-06-18 09:59:18
JComponents没有出现有图片背景?我的部件没出现。我该怎么解决这个问题?代码:import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.image.BufferedImage; import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.*;public class login implements ActionListener{     JTextField gusername;     JTextField gpassword;     static String username;     static String password;     void logini() throws IOException {         JFrame window = new JFrame("Login");         window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         window.setSize(300, 250);         window.setResizable(false);         window.setVisible(true);         JPanel mainp = new JPanel(new GridBagLayout());         GridBagConstraints c = new GridBagConstraints();         window.add(mainp);         BufferedImage myPicture = ImageIO.read(new File("c:\\bgd.png"));         JLabel picLabel = new JLabel(new ImageIcon( myPicture ));         mainp.add(picLabel, c);         c.gridx = 0;         c.gridy = 1;         gusername = new JTextField();         gusername.setText("Username");         mainp.add(gusername, c);         c.gridx = 0;         c.gridy = 2;         gpassword = new JTextField();         gpassword.setText(" password ");         mainp.add(gpassword, c);         c.gridx = 0;         c.gridy = 3;         JButton login = new JButton("Login");         mainp.add(login, c);         login.addActionListener(this);         login.setActionCommand("ok");     }     public void actionPerformed(ActionEvent e) {         if (e.getActionCommand().equalsIgnoreCase("ok")){             try {                 this.username = (gusername.getText());                 this.password = (gpassword.getText());                 System.out.println("0");             }             catch(NumberFormatException ex){                 System.out.println("ERROR: Could not preform function: 7424");             }         }     }}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 510 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号