java中添加背景_java中如何增加背景图片
我的程序代碼如下,試了加背景的方法雖然程序沒(méi)有錯(cuò)誤,但是背景還是顯示不出來(lái),按鈕的setsize好像也不起作用,希望高人能助一臂之力,小女子先寫過(guò)各位了:、、、、importjava.awt....
我的程序代碼如下,試了加背景的方法雖然程序沒(méi)有錯(cuò)誤,但是背景還是顯示不出來(lái),按鈕的setsize好像也不起作用,希望高人能助一臂之力,小女子先寫過(guò)各位了:、、、、 import java.awt.*; import javax.swing.*; public class MainFrame extends JFrame { public static void main(String[] args) { JFrame frame=new JFrame("補(bǔ)考管理系統(tǒng)"); frame.setSize(300,200); frame.setBackground(Color.gray); /*((JPanel) frame.getContentPane()).setOpaque(false); // Winter.jpg這個(gè)圖片的位置要跟當(dāng)前這個(gè)類是同一個(gè)包下 ImageIcon img = new ImageIcon("c://aaa.jpeg"); JLabel background = new JLabel(img); frame.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE)); background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight()); */ ImageIcon img = new ImageIcon("//practice//src//img//login_mainbg.jpg");//這是背景圖片 JLabel imgLabel = new JLabel(img);//將背景圖放在標(biāo)簽里。 frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));//注意這里是關(guān)鍵,將背景標(biāo)簽添加到j(luò)fram的LayeredPane面板里。 imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());//設(shè)置背景標(biāo)簽的位置 //JFrame frame=new JFrame("補(bǔ)考管理系統(tǒng)"); // frame.addComponent(new FrameListener());//添加監(jiān)聽(tīng)器 //設(shè)置用戶關(guān)閉框架時(shí)的響應(yīng)動(dòng)作 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel title=new JLabel("歡迎進(jìn)入補(bǔ)考管理系統(tǒng)"); Font fnt=new Font("Serief",Font.BOLD+Font.ITALIC,40); title.setFont(fnt); Panel userpan=new Panel();//用戶信息面板 JLabel userlab=new JLabel("用戶名:"); JLabel mmlab=new JLabel("密碼:"); JTextField username=new JTextField(); TextField password=new TextField(6); JButton login=new JButton("登錄"); JButton Reset=new JButton("重置"); password.setEchoChar('*'); //login.resize(5,5); // Reset.resize(5,5); userpan.setSize(100,100); userpan.setLocation(300,300); userpan.setLayout(new GridLayout(3,2,0,5)); //3行2列的網(wǎng)格布局管理器 userpan.add(userlab); userpan.add(username); userpan.add(mmlab); userpan.add(password); userpan.add(login); userpan.add(Reset); frame.add(title,BorderLayout.NORTH); frame.add(userpan,BorderLayout.CENTER); frame.setResizable(false); frame.setVisible(true); } }
展開(kāi)
總結(jié)
以上是生活随笔為你收集整理的java中添加背景_java中如何增加背景图片的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 常见php面试题,常见的 PHP 面试题
- 下一篇: MySQL8怎么设置时区为东八区_mys