日期:2014-05-20  浏览次数:20890 次

大家帮忙看一下我的java小程序,为何jpanel上没有显示东西
package homework.dao;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.IOException;
import java.nio.ByteOrder;

import javax.imageio.stream.IIOByteBuffer;
import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class textfiled extends JFrame{
public textfiled()
{
Container c=getContentPane();
JPanel jl = new JPanel(){
public void paintComponent(Graphics g) {
ImageIcon icon = new ImageIcon("src/lie.png");
  g.drawImage(icon.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
}
};
  jl.setOpaque(false);
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
this.setVisible(true);
  this.setTitle("MD5加密");
this.setBounds((width-400)/2,(height-400)/2,400,400);
this.setLayout(null);

final JTextField jt=new JTextField("040940207李孟杰",50);
jt.setBounds(100, 50, 240, 50);
final JButton jb=new JButton("MD5加密");
jb.setBounds(140, 150, 100, 30);
c.add(jl);
jl.add(jt);
jl.add(jb);
jt.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub

jt.setText(" ");  


}
});
jb.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String str = jt.getText();
md5 getMD5 = new md5();
jt.setText(md5.GetMD5Code("str"));
}
});
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str;
new textfiled().setVisible(true);


}

}


------解决方案--------------------
你的JPanel需要设置大小。

------解决方案--------------------
你的JPanel需要设置大小。