GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Aug-2006, 11:24
Skynet159 Skynet159 is offline
New Member
 
Join Date: Aug 2006
Posts: 4
Skynet159 is on a distinguished road

Load image problem, need help!!!


Hi i have been given a task at school, this is the task:

Design and implement a GUI program that will allow a user to load and display one of 2 images. The images should be of your own choosing.

You should provide a text area to display the images.

You should provide three buttoms, two of the buttons will load the images and the third will clear the text area.

So far I have been able to do the GUI with the textarea and the three buttons, but i have no idea how to load the image after the button is pressed
If any one knows please help me, I hane only few more days to complete the task thanx in advance
  #2  
Old 13-Aug-2006, 12:20
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Load image problem, need help!!!


Please see the Guidelines Thread

especially #1, and check 1.A

This will be help us help you since we have no way to tell if you are using AWT, SWING, etc. Start with that, and we'll go from there.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 13-Aug-2006, 13:14
Skynet159 Skynet159 is offline
New Member
 
Join Date: Aug 2006
Posts: 4
Skynet159 is on a distinguished road

Re: Load image problem, need help!!!


I am using swing and iam prohramming in Editplus
  #4  
Old 13-Aug-2006, 13:17
Skynet159 Skynet159 is offline
New Member
 
Join Date: Aug 2006
Posts: 4
Skynet159 is on a distinguished road

Re: Load image problem, need help!!!


i can post the source code what i have so far, do you need it?
thanx for the reply
  #5  
Old 13-Aug-2006, 14:41
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Load image problem, need help!!!


Sure, go ahead. I don't need it, but the sole purpose is to help you along.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #6  
Old 13-Aug-2006, 15:01
Skynet159 Skynet159 is offline
New Member
 
Join Date: Aug 2006
Posts: 4
Skynet159 is on a distinguished road

Re: Load image problem, need help!!!


well some of the things were some test so maybe they are pointless
You also need to put into one folder with images called img and img2 but the GUI should work without them anyway



JAVA Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public final class AreaTest extends JFrame
{
	private JButton b1, b2, b3; //Registering number buttons and operational buttons
	private JPanel buttonLayout; //creating Panel for button layout
	private int a=0;
	
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	Image image = toolkit.createImage("img.jpg");	
		

    public AreaTest()
    {
        Container container = getContentPane();
        container.setLayout(new BorderLayout());

        
        JPanel buttonLayout = new JPanel();
        buttonLayout.setLayout(new GridLayout(3, 1));
        
        JTextArea textArea = new JTextArea()
        {
            
            {setOpaque(false);}
            public void paintComponent (Graphics g)
            {
                
                
                g.drawImage(image, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
                super.paintComponent(g);
            }
          
        };
        
        b1 = new JButton("one"); //creation of a button using command JButton; doing the same with the rest of the buttons
	b1.setBackground(Color.orange); //setting button color to orange
	b2 = new JButton("two"); 
	b2.setBackground(Color.orange);
	b3 = new JButton("three");
	b3.setBackground(Color.orange);
	
	b1.addActionListener(new ActionListener() //adding function to a particular button
		{	public void actionPerformed(ActionEvent e)
			{
				
			}
		});

	
        container.add(textArea);
        container.add(buttonLayout, "South");
        buttonLayout.add(b1); //adding registered buttons in order to make them appear inside the calculator
		buttonLayout.add(b2);
		buttonLayout.add(b3);
		
		
    }


    public static void main(String[] args)
    {
        
        AreaTest areaTest = new AreaTest();
        areaTest.setSize(300, 300);
        areaTest.setLocation(350,230);
        //areaTest.setResizable(false);
        areaTest.setTitle("Area test");
        areaTest.setVisible(true);
    }
}
Last edited by cable_guy_67 : 13-Aug-2006 at 16:50. Reason: Please surround your Java code with [java] ... [/java]
  #7  
Old 14-Aug-2006, 09:21
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Load image problem, need help!!!


Ok, you have the right idea, but just need some minor modifications.

1. move the JTextArea declaration out of the constructor to have class scope.
2. keep the 'image' declaration at class scope [where it already is now], but move the assignment portion (the image to show) to the button's actionPerformed() call.
3. after assigning the image, call textArea.repaint().

Basically, for 2 & 3, the actionPerformed() will have two statements: one that assigns the image, and the other does the repaint to update the textArea.

The only part I have not covered is clearing. I'll leave that little bit for you to do; however, if you run into problems, just post back with your updated code. (place it between java tags [see the bottom of post #6]).
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 14-Aug-2006 at 10:40.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display problem in firefox and opera batrsau Web Design Forum 4 09-Dec-2005 03:18
GIM gidedit - a fltk fluid resize project cable_guy_67 FLTK Forum 2 01-Jun-2005 15:00
Display filesystem to load a file and drawing an image maveganzones FLTK Forum 3 07-Apr-2005 11:15
serious problem with my PC,Local Security Policy cant load codavid Computer Software Forum - Windows 14 31-Mar-2005 11:17
Checking source codes of image, audio and video files onauc C Programming Language 5 26-Feb-2005 21:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:32.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.