Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: How to extract image to be put in JPanel using JButton

  1. #1
    nanj is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Smile How to extract image to be put in JPanel using JButton

    Hi,
    Iam very new with java.
    i need your help to design this things.
    I just prepare the GUI for this.
    I dont know to add the function into the Jbutton.
    I really hope that someone will help me. :)

    import java.io.*;
    import java.awt.Color;

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;

    public class GUI {

    public static void main (String[] args){

    ImageIcon image = new ImageIcon("");

    Color myColor = new Color (150,200,150);

    JFrame jf = new JFrame("Test GUI");
    jf.setSize(600,600);

    JPanel jp = new JPanel();
    jp.setSize(560,480);
    jp.setLocation(10,10);

    jf.getContentPane().add(jp);

    JButton jb = new javax.swing.JButton("Load Image");
    jb.setSize (120,40);
    jb.setLocation(240,500);

    jf.getContentPane().add(jb);

    JLabel label = new JLabel("");

    JLabel imageLabel = new JLabel(image);

    label.setOpaque(true);
    label.setBackground(myColor);

    jf.add(imageLabel);
    jf.add(label);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setVisible(true);

    }


    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: How to extract image to be put in JPanel using JButton

    Quote Originally Posted by nanj View Post
    Hi,
    Iam very new with java.
    i need your help to design this things.
    I just prepare the GUI for this.
    I dont know to add the function into the Jbutton.
    I really hope that someone will help me. :)
    Oracle can help you. To add functionality to a JButton, you would add an ActionListener to the button. The Oracle tutorials will show you how:
    How to Use Buttons
    How to Write an ActionListener

    Also please see my signature link below on how to use code tags. Your code will be unreadable until you use them with well-formatted code.
    nanj likes this.

Similar Threads

  1. Image extract
    By tomalakis in forum New To Java
    Replies: 4
    Last Post: 12-26-2012, 08:46 PM
  2. How extract data from image file
    By Balasubrahmanyam in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-27-2011, 08:01 AM
  3. Open JPanel with JButton
    By web_dev in forum New To Java
    Replies: 7
    Last Post: 06-13-2011, 11:25 PM
  4. Adding JButton to JPanel
    By razmyasdfg in forum AWT / Swing
    Replies: 8
    Last Post: 05-24-2011, 12:03 AM
  5. Problem on adding JButton on JPanel NEED HELP
    By boisk in forum AWT / Swing
    Replies: 15
    Last Post: 03-15-2009, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •