1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Graphics;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
/**
* Created by IntelliJ IDEA.
* User: bebe
* Date: 12-Jun-2006
* Time: 08:34:15
* To change this template use File | Settings | File Templates.
*/
public class Test extends JPanel {
private JPanel myPanel1 = new JPanel() {
Image image = null;
protected void paintComponent(Graphics g) {
super.paintComponent(g); //To change body of overridden methods use File | Settings | File Templates.
if (image == null) {
try {
image = javax.imageio.ImageIO.read(new URL("http://www.google.be/images/logo_sm.gif"));
} catch (MalformedURLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this);
}
};
private JPanel myPanel2 = new JPanel();
private JPanel myPanel3 = new JPanel();
public Test() {
initGui();
}
private void initGui() {
setLayout(new GridBagLayout());
Border myBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
myPanel1.setBorder(myBorder);
myPanel2.setBorder(myBorder);
myPanel3.setBorder(myBorder);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0;
gbc.weighty = 0.6;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 5, 5, 5);
this.add(myPanel1, gbc);
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.weightx = 0.5;
gbc.weighty = 0.4;
this.add(myPanel2, gbc);
gbc.gridx = 1;
this.add(myPanel3, gbc);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Test());
frame.setSize(new Dimension(400, 300));
frame.setVisible(true);
}
} |
Partager