import java.awt.*; import java.awt.event.*; import javax.swing.*; public class demoimagen extends JFrame implements ActionListener { private JButton boton; private JPanel panel; private JTextField capoarchivo; private int posicionx=0,posiciony=0; public static void main(String[] args ) { demoimagen marco=new demoimagen(); marco.setSize(300,300); marco.crearGUI(); marco.setVisible(true); } public void crearGUI() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container ventana=getContentPane(); ventana.setLayout(new FlowLayout()); panel=new JPanel(); panel.setPreferredSize(new Dimension(400,400)); panel.setBackground(Color.white); ventana.add(panel); capoarchivo =new JTextField(20); ventana.add(capoarchivo); boton=new JButton("pikale"); ventana.add(boton); boton.addActionListener(this); }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub ImageIcon miImagen= new ImageIcon("carro2.gif"); Graphics papel = panel.getGraphics(); miImagen.paintIcon(this,papel,posicionx,posiciony); posicionx=posicionx+30; posiciony=posiciony+30; }
}
|