日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java主界面设置背景图片_java 窗体设置背景图片问题?(附上登陆界面代码,我想加个背景图片,求大神帮忙改改)...

發布時間:2024/9/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java主界面设置背景图片_java 窗体设置背景图片问题?(附上登陆界面代码,我想加个背景图片,求大神帮忙改改)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

java 窗體設置背景圖片問題?(附上登陸界面代碼,我想加個背景圖片,求大神幫忙改改)

關注:223??答案:4??mip版

解決時間 2021-01-26 22:09

提問者非莪莫屬

2021-01-26 02:59

import java.awt.event.WindowAdapter ;

import java.awt.event.ActionListener ;

import java.awt.event.WindowEvent ;

import java.awt.event.ActionEvent ;

import java.awt.Color ;

import java.awt.Font ;

import javax.swing.JFrame ;

import javax.swing.JButton ;

import javax.swing.JLabel ;

import javax.swing.JTextField ;

import javax.swing.JPasswordField ;

class LoginCheck{

private String name ;

private String password ;

public LoginCheck(String name,String password){

this.name = name ;

this.password = password ;

}

public boolean validate(){

if("mwb".equals(name)&&"mwb".equals(password)){

return true ;

}else{

return false ;

}

}

};

class ActionHandle{

private JFrame frame = new JFrame("Welcome To My FinanceManageSystem") ;

private JButton submit = new JButton("登陸");

private JButton reset = new JButton("重置");

private JLabel nameLab = new JLabel("用戶名:") ;

private JLabel passLab = new JLabel("密 碼:") ;

private JLabel infoLab = new JLabel("用戶登陸系統") ;

private JTextField nameText = new JTextField(10) ;

private JPasswordField passText = new JPasswordField();

public ActionHandle(){

Font fnt = new Font("Serief",Font.ITALIC + Font.BOLD,12) ;

infoLab.setFont(fnt) ;// 設置標簽的顯示文字

submit.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

if(e.getSource()==submit){

String tname = nameText.getText() ;

String tpass = new String(passText.getPassword()) ;

LoginCheck log = new LoginCheck(tname,tpass) ;

if(log.validate()){

infoLab.setText("登陸成功,歡迎光臨!") ;

}else{

infoLab.setText("登陸失敗,錯誤的用戶名或密碼!") ;

}

}

}

}) ;

reset.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

if(e.getSource()==reset){

nameText.setText("") ;

passText.setText("") ;

infoLab.setText("用戶登陸系統") ;

}

}

}) ;

frame.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(1) ;

}

}) ;// 加入事件

frame.setLayout(null) ;

nameLab.setBounds(650,300,60,20) ;

passLab.setBounds(650,325,60,20) ;

infoLab.setBounds(650,360,220,30) ;

nameText.setBounds(710,300,100,20) ;

passText.setBounds(710,325,100,20) ;

submit.setBounds(810,300,60,20) ;

reset.setBounds(810,325,60,20) ;

frame.add(nameLab) ;

frame.add(passLab) ;

frame.add(infoLab) ;

frame.add(nameText) ;

frame.add(passText) ;

frame.add(submit) ;

frame.add(reset) ;

frame.setSize(280,130) ;

frame.setBackground(Color.WHITE) ;

frame.setSize(1000,500);

frame.setLocation(200,150) ;

frame.setVisible(true) ;

}

}

public class Login{

public static void main(String args[]){

new ActionHandle() ;

}

}

在eclipse中運行

最佳答案

二級知識專家柒夏錦年

2021-01-26 03:39

給你加完了,繼承PANEL類,得寫paint或paintComponent方法。

代碼如下。

---------------------------------------------------------------------------------------------------

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

class LoginCheck {

private String name;

private String password;

public LoginCheck(String name, String password) {

this.name = name;

this.password = password;

}

public boolean validate() {

if ("mwb".equals(name) && "mwb".equals(password)) {

return true;

} else {

return false;

}

}

};

class ActionHandle {

private JFrame frame = new JFrame("Welcome To My FinanceManageSystem");

private JButton submit = new JButton("登陸");

private JButton reset = new JButton("重置");

private JLabel nameLab = new JLabel("用戶名:");

private JLabel passLab = new JLabel("密 碼:");

private JLabel infoLab = new JLabel("用戶登陸系統");

private JTextField nameText = new JTextField(10);

private JPasswordField passText = new JPasswordField();

public ActionHandle() {

Font fnt = new Font("Serief", Font.ITALIC + Font.BOLD, 12);

infoLab.setFont(fnt); // 設置標簽的顯示文字

submit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (e.getSource() == submit) {

String tname = nameText.getText();

String tpass = new String(passText.getPassword());

LoginCheck log = new LoginCheck(tname, tpass);

if (log.validate()) {

infoLab.setText("登陸成功,歡迎光臨!");

} else {

infoLab.setText("登陸失敗,錯誤的用戶名或密碼!");

}

}

}

});

reset.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (e.getSource() == reset) {

nameText.setText("");

passText.setText("");

infoLab.setText("用戶登陸系統");

}

}

});

frame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(1);

}

}); // 加入事件

frame.setLayout(null);

nameLab.setBounds(650, 300, 60, 20);

passLab.setBounds(650, 325, 60, 20);

infoLab.setBounds(650, 360, 220, 30);

nameText.setBounds(710, 300, 100, 20);

passText.setBounds(710, 325, 100, 20);

submit.setBounds(810, 300, 60, 20);

reset.setBounds(810, 325, 60, 20);

frame.add(nameLab);

frame.add(passLab);

frame.add(infoLab);

frame.add(nameText);

frame.add(passText);

frame.add(submit);

frame.add(reset);

frame.setSize(280, 130);

frame.setBackground(Color.WHITE);

frame.setSize(1000, 500);

frame.setLocation(200, 150);

ImagePanel panel = new ImagePanel();

panel.setBounds(0, 0, 600, 400);

frame.add(panel);

frame.setVisible(true);

}

}

public class Login {

public static void main(String args[]) {

new ActionHandle();

}

}

class ImagePanel extends JPanel {

protected void paintComponent(Graphics g) {

super.paintComponent(g);

ImageIcon icon = new ImageIcon("D:\\1.jpg");

g.drawImage(icon.getImage(),0,0,null);

}

}

全部回答

1樓相忘于江湖

2021-01-26 06:44

要使用JPanel類,繼承這個類,覆寫其中的PaintCompentent方法即可

2樓指間的落寞

2021-01-26 05:12

看不懂。。。。

3樓何必執著

2021-01-26 04:55

a

我要舉報

如以上問答內容為低俗/色情/暴力/不良/侵權的信息,可以點下面鏈接進行舉報,我們會做出相應處理,感謝你的支持!

→點此我要舉報以上信息!←

推薦資訊

大家都在看

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的java主界面设置背景图片_java 窗体设置背景图片问题?(附上登陆界面代码,我想加个背景图片,求大神帮忙改改)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。