Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package imageTest;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class newImage {
- JFrame frame = new JFrame();
- public newImage(){
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(800, 800);
- frame.setVisible(true);
- frame.setLayout(null);
- JButton btn = new JButton();
- btn.setText("Show Image");
- btn.setBounds(100, 100, 70, 70);
- btn.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- JLabel lbl = new JLabel();
- lbl.setIcon(new ImageIcon("C:\\Users\\bbol1765\\Downloads\\jpg_file.png"));
- lbl.setBounds(190, 150, 150, 150);
- frame.add(lbl);
- SwingUtilities.updateComponentTreeUI(frame);
- }
- });
- frame.add(btn);
- }
- public static void main(String args[]){
- new newImage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement