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
| public class SwingImageButton extends JFrame implements ActionListener
{
//private Image theImage;
private JButton button;
private JTextArea textArea;
private JTextField status;
private JCheckBox editable;
private JComboBox colorBox;
private boolean isTextEditable = true;
//private JComboBo
private BufferedImage image;
public SwingImageButton()
{
super("Swing Button Example");
/*Load an image */
String filename="portable.JPG";
image = new BufferedImage(290, 470, BufferedImage.TYPE_INT_RGB);
// create an image by reading in the PNG, GIF, or JPEG from a filename
try { image = ImageIO.read(new File(filename)); }
catch(IOException e) {
e.printStackTrace();
throw new RuntimeException("Could not open file: " + filename);
}
// status TextField
this.status = new JTextField();
this.updateStatus("Application Started.");
// main area, with scrolling and wrapping
this.textArea = new JTextArea(20,40);
JScrollPane p = new JScrollPane(this.textArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.textArea.setWrapStyleWord(true);
this.getContentPane().add("North",p);
this.pack(); //set the size of the frame according
//to the component's preferred sizes
this.show(); //make the frame visible
}
private void updateStatus(String theStatus)
{
this.status.setText("Status: " + theStatus);
}
public void actionPerformed(ActionEvent e)
{
}
public void paintComponent(Graphics g)
{
//super(g);
Graphics2D g2D=(Graphics2D )g;
Graphics2D g2d = (Graphics2D)this.image.getGraphics();
//g2D.drawImage(this.image,20,40,this);
//super.paintComponent(g);
// g.drawImage( this.tempImage, 10, 10, this);
}
public static void main(String args[])
{
new SwingImageButton();
}
} |
Partager