Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: what wrong with my code?

  1. #1
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default what wrong with my code?

    this my code :

    Java Code:
    import java.sql.*;
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.image.*;
    import java.awt.event.*;
    
    public class UploadImage extends JFrame{
    Image img;
    JTextField text1=new JTextField();
    JTextField text2=new JTextField();
    JButton browse1, browse2;
    JPanel panel = new JPanel();
    JLabel label1 = new JLabel();
    JLabel label2 = new JLabel();
    File file = null;
    String path="";
    
    public UploadImage() {
        
    setTitle("DECODE SECTION");
    setBackground(Color.LIGHT_GRAY ); 
    panel.setBackground(Color.LIGHT_GRAY);
    
    browse1 = new JButton("Browse");
    label1 = new JLabel ("Select original photo");
    label1.setBounds(10,30,150,25);
    label1.setFont(new Font("Serif", Font.ITALIC, 14));
    text1.setBounds(140,30,310,25);
    browse1.setBounds(460,30,100,25);
    
    browse2 = new JButton("Browse");
    label2 = new JLabel ("Select stego photo");
    label2.setBounds(10,70,150,25);
    label2.setFont(new Font("Serif", Font.ITALIC, 14));
    text2.setBounds(140,70,310,25);
    browse2.setBounds(460,70,100,25);
    
    add(panel);
    setSize(600,500);
    
    add(text1);
    add(browse1);
    add(text2);
    add(browse2);
    add(label1);
    add(label2);
    setVisible(true);
    
    browse1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    chooser.addChoosableFileFilter(new ImageFileFilter());
    int returnVal = chooser.showOpenDialog(null);
    
    if(returnVal == JFileChooser.APPROVE_OPTION) {
    file = chooser.getSelectedFile();
     path=file.getPath();
    //ImageIcon icon=new ImageIcon(path);
    //label.setIcon(icon);
    text1.setText(path);
    
    repaint();
    }
    }
    });
    
    browse2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    chooser.addChoosableFileFilter(new ImageFileFilter());
    int returnVal = chooser.showOpenDialog(null);
    
    if(returnVal == JFileChooser.APPROVE_OPTION) {
    file = chooser.getSelectedFile();
     path=file.getPath();
    //ImageIcon icon=new ImageIcon(path);
    //label.setIcon(icon);
    text2.setText(path);
    
    repaint();
    }
    }
    });
    
    public static void main(String[] args) {
     new UploadImage();
    }
    
    }
    class ImageFileFilter extends javax.swing.filechooser.FileFilter {
    public boolean accept(File file) {
    if (file.isDirectory()) return false;
    String name = file.getName().toLowerCase();
    return (name.endsWith(".jpg") || name.endsWith(".png")|| name.endsWith(".gif"));
    }
    public String getDescription() { return "Images (*.gif,*.bmp, *.jpg, *.png )"; }
    }
    the output:
    what wrong with my code?-untitled.png

    why the output be like this?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: what wrong with my code?

    why the output be like this?
    Well...because it was programmed that way. You should provide more information...for instance, what you expect, want, the requirements, errors, exceptions, yadayadayada....

  3. #3
    aelynne is offline Member
    Join Date
    Oct 2011
    Posts
    15
    Rep Power
    0

    Default Re: what wrong with my code?

    i want the label "select stego photo' to be beside the textfield. just like above. but not works. why?

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: what wrong with my code?

    I think you should first learn about using the layout manager. So that you'll understand how to place the swing component on the screen. Here is a good tutorial to start with A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: what wrong with my code?

    Forum Rules -- especially the third paragraph

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: what wrong with my code?

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default Re: what wrong with my code?

    Change label2.setBounds(10,40,150,25)

    you can give more value to y-axis...
    setBounds working like (x,y,x1,y1)
    above code (x=10,y=40,x1=150,y1=25)

    -----------------------------------------
    mcajavaprogramer

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: what wrong with my code?

    Quote Originally Posted by mcajavaprogramer View Post
    Change label2.setBounds(10,40,150,25)

    you can give more value to y-axis...
    setBounds working like (x,y,x1,y1)
    above code (x=10,y=40,x1=150,y1=25)
    Don't use setBounds(...). And the explanation is also wrong.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default Re: what wrong with my code?

    ohh ok..

    may be explanation is wrong but the guy who wrote this code also use this method..

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: what wrong with my code?

    Quote Originally Posted by mcajavaprogramer View Post
    the guy who wrote this code also use this method..
    Unfortunately, that code started its life on one of the worst so-called tutorial sites on the internet. Which through some kind of scheming and manipulation -- there can be no other explanation -- enjoys a high Google ranking on just about any Java related query.

    db
    mcajavaprogramer likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. what is wrong with my code
    By amrmb09 in forum New To Java
    Replies: 7
    Last Post: 02-11-2011, 05:10 PM
  2. What's going wrong with this code?
    By Suurisa in forum New To Java
    Replies: 5
    Last Post: 10-19-2009, 11:59 PM
  3. what's the wrong in this Code
    By the swan in forum AWT / Swing
    Replies: 1
    Last Post: 04-04-2009, 04:27 AM
  4. What's wrong with this code?
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 11-29-2008, 05:44 PM
  5. what's wrong with this code?
    By agenteleven in forum Advanced Java
    Replies: 5
    Last Post: 10-07-2008, 11:26 AM

Posting Permissions

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