There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
image/icon as an button


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
06-Mar-2007, 06:43 AM #1
image/icon as an button
Hi,
I have somehow figured out how to have an image as a button ...but the image seems to be a bit big...so Im trying to reduce the size of it....any helps???the code is below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*<applet code=imagebutn.class width=500 height=500>
</applet>*/
public class imagebutn extends JApplet implements ActionListener
{
Container c=getContentPane();
JLabel l=new JLabel("type");
JTextField t=new JTextField(10);
Icon i=new ImageIcon("doggy1.gif");
JButton b=new JButton(i);
public void init()
{
c.setLayout(new FlowLayout());
c.add(l);
c.add(t);
c.add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent a)
{
l.setText(t.getText());
}
}
Chicon's Avatar
Computer Specs
Distinguished Member with 6,587 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
06-Mar-2007, 08:00 AM #2
Code:
 JButton b = new JButton();

    public void init() {
        c.setLayout(new FlowLayout());
        c.add(l);
        c.add(t);
        b.setIcon(i);
        b.setSize(i.getIconWidth(),i.getIconHeight());
        c.add(b);
        b.addActionListener(this);
    }
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
06-Mar-2007, 08:35 AM #3
giving the parameters
Hi Chicon,
thanks for the replies.I have incorporated the statements that you had mentioned, in my code.But how do I compile/interpret it?Where do I need to specify the values for height & width?
Chicon's Avatar
Computer Specs
Distinguished Member with 6,587 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
06-Mar-2007, 02:50 PM #4


I'm afraid I don't understand your question.
I guess you have to compile the program in the way you're used to.
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
06-Mar-2007, 11:38 PM #5
compilation
Hi,
This is the issue.I normally compile as below:
javac imagebutn.java
appletviewer imagebutn.java

Now where do I give the values for height & width so that I can set the size of the icon?Hope you got my problem?
Thanks,
Cali
Chicon's Avatar
Computer Specs
Distinguished Member with 6,587 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
07-Mar-2007, 01:34 AM #6
You don't need to manually set the size of the icon.
In your command : Icon i = new ImageIcon("doggy1.gif");, i will get the size of the picture 'doggy1.gif'.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.