0
这里我的面板上的按钮只有当我把我的鼠标放在他们和秘密密码按钮和JTextfield甚至然后不可见时才可见。请提出一些想法来解决这个问题。我有三个按钮和标签和文本字段。如何在java面板上设置背景图像,使我的按钮清晰可见?
public class FileOperation extends JFrame
{
private Player player;
private File file;
private class BackgroundPanel extends Panel
{
Image img;
public BackgroundPanel()
{
try
{
img = Toolkit.getDefaultToolkit().createImage("17.jpg");
}
catch(Exception e){/*handled in paint()*/}
}
@Override
public void paint(Graphics g)
{
super.paint(g);
if(img != null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);
else g.drawString("No Image",100,100);
}
}
public FileOperation()
{
super("File Protection Tool");
BackgroundPanel panel = new BackgroundPanel();
panel.setLayout (null);
JLabel label5=new JLabel("SecretPassword");
final JTextField hashkey = new JTextField(15);
JButton openFilee = new JButton("Open file to encrypt");
openFilee.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openFile(0,hashkey);
}
});
JButton openFiled = new JButton("Open file to decrypt");
openFiled.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent d)
{
openFile(1,hashkey);
}
});
JButton openFilefol = new JButton("Choose folder to lock");
openFilefol.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent d)
{
openFilefol();
}
});
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth/2, screenHeight/2);
setLocation(screenWidth/4, screenHeight/4);
setTitle("FileEncrypt");
hashkey.setBounds(200,210,150,20);
label5.setBounds(100,210,150,20);
openFilee.setBounds(50,120,190,20);
openFiled.setBounds(300,120,190,20);
openFilefol.setBounds(80,240,190,20);
panel.add(openFilee);
panel.add(openFiled);
panel.add(openFilefol);
panel.add(label5);
panel.add(hashkey);
panel.setVisible(true);
getContentPane().add(panel);
}
感谢lot.corrected :) – Sam