help Displaying shapes after button is clicked

help

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 5616 Views - Last Post: 09 April 2010 - 07:32 AM Rate Topic: -----

#1 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

help Displaying shapes after button is clicked

Posted 08 April 2010 - 08:16 AM

Okay, my assignment is to Write a program with four buttons: “Show Rectangle”, “Show Oval”, “Show Arc”, “Show Polygon” When you click a button, a corresponding panel (RectPanel, OvalPanel, ArcPanel and PolyPanel) is shown in the frame.

this is what i have so far

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.awt.*;
public class RAC11_01 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel panel1 = new JPanel ();
	   JPanel panel2 = new JPanel ();
		
	   
	    panel1.setBackground(Color.BLACK);
	   frame.getContentPane().add(panel1);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	    JButton button2 = new JButton("Show Oval");
	    
	    panel1.add(button1);
	    panel1.add(button2);
	  
	    
	    frame.setVisible(true);
	    panel2.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(panel2);

	    JButton button4 = new JButton("Show Arc");
	    JButton button5 = new JButton("Show Polygon");
	   
	 
	    panel2.add(button4);
	    panel2.add(button5);
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	}

}



can someone help me and show me where and how to set this up, or an example of just 1 button that does this so i can see how it works and looks.

Thanks guys! ryclegman

This post has been edited by ryclegman: 08 April 2010 - 08:17 AM


Is This A Good Question/Topic? 0
  • +

Replies To: help Displaying shapes after button is clicked

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 08:31 AM

you should add ActionListeners to the buttons.
these tutorials may help:
ActionListeners:
http://java.sun.com/...onlistener.html
JButtons:
http://java.sun.com/...nts/button.html
Was This Post Helpful? 0
  • +
  • -

#3 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 08:48 AM

View Postjapanir, on 08 April 2010 - 07:31 AM, said:

you should add ActionListeners to the buttons.
these tutorials may help:
ActionListeners:
http://java.sun.com/...onlistener.html
JButtons:
http://java.sun.com/...nts/button.html

okay but how do i change the button into an image... of a blue rectangle
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • Joined: 24-September 08

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 08:58 AM

You want to change the button into the shape? Why not just draw it in a panel above? So when they click it, just delete the instance of the previous shape and create an instance of the new shape and just call the repaint method. (You need graphics and since I just skimmed I didn't see one).
Was This Post Helpful? 0
  • +
  • -

#5 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:03 AM

View PostNeoTifa, on 08 April 2010 - 07:58 AM, said:

You want to change the button into the shape? Why not just draw it in a panel above? So when they click it, just delete the instance of the previous shape and create an instance of the new shape and just call the repaint method. (You need graphics and since I just skimmed I didn't see one).

yes that what i need to do... just draw it in the panel.. where it says show rectangle.. the text would delete and a small rectangle would appear there after they clicked it..

this is what i have so far

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.awt.*;


public class RAC11_01 implements ActionListener { 
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel RectPanel = new JPanel ();
	   JPanel OvalPanel = new JPanel ();
	   JPanel ArcPanel = new JPanel ();
	   JPanel PolyPanel= new JPanel  ();
		
//----------------------------------------------------------------------	   panel1
	   RectPanel.setBackground(Color.BLACK);
	   frame.getContentPane().add(RectPanel);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	    
	    button1.addActionListener(this);
	    RectPanel.add(button1);
	    
	     frame.setVisible(true);
	     
//---------------------------------------------------------------------------	panel2     
	    
	     OvalPanel.setBackground(Color.red);
		   frame.getContentPane().add(OvalPanel);
		   
		   frame.getContentPane().setLayout(new FlowLayout());
		    frame.setSize(300,150);
		    
		    
		    JButton button2 = new JButton("Show Oval");
		    button2.addActionListener(this);
	
		    OvalPanel.add(button2);
		    
		    
		    frame.setVisible(true);
	     
	     
//--------------------------------------------------------------------------	     panel3
		    ArcPanel.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(ArcPanel);

	    JButton button3 = new JButton("Show Arc");
	   
	   
	 
	    ArcPanel.add(button3);
	   
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
//--------------------------------------------------------------------------------------panel4
	   PolyPanel.setBackground(Color.blue);
	   
	    frame.getContentPane().add(PolyPanel);

	    JButton button4 = new JButton("Show Poly");
	    
	   
	 
	    PolyPanel.add(button4);
	    	
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	   
	   
	}
			
//----------------------------------------------------------
				public void actionPerformed(ActionEvent evt)
				{
					button1.setText("I've been clicked!");				
					}
			}

  


below the 4th panel i was just trying to get it to say something if you were wondering..
Was This Post Helpful? 0
  • +
  • -

#6 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:13 AM

View Postryclegman, on 08 April 2010 - 08:03 AM, said:

View PostNeoTifa, on 08 April 2010 - 07:58 AM, said:

You want to change the button into the shape? Why not just draw it in a panel above? So when they click it, just delete the instance of the previous shape and create an instance of the new shape and just call the repaint method. (You need graphics and since I just skimmed I didn't see one).

yes that what i need to do... just draw it in the panel.. where it says show rectangle.. the text would delete and a small rectangle would appear there after they clicked it..

this is what i have so far

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.awt.*;


public class RAC11_01 implements ActionListener { 
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel RectPanel = new JPanel ();
	   JPanel OvalPanel = new JPanel ();
	   JPanel ArcPanel = new JPanel ();
	   JPanel PolyPanel= new JPanel  ();
		
//----------------------------------------------------------------------	   panel1
	   RectPanel.setBackground(Color.BLACK);
	   frame.getContentPane().add(RectPanel);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	    
	    button1.addActionListener(this);
	    RectPanel.add(button1);
	    
	     frame.setVisible(true);
	     
//---------------------------------------------------------------------------	panel2     
	    
	     OvalPanel.setBackground(Color.red);
		   frame.getContentPane().add(OvalPanel);
		   
		   frame.getContentPane().setLayout(new FlowLayout());
		    frame.setSize(300,150);
		    
		    
		    JButton button2 = new JButton("Show Oval");
		    button2.addActionListener(this);
	
		    OvalPanel.add(button2);
		    
		    
		    frame.setVisible(true);
	     
	     
//--------------------------------------------------------------------------	     panel3
		    ArcPanel.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(ArcPanel);

	    JButton button3 = new JButton("Show Arc");
	   
	   
	 
	    ArcPanel.add(button3);
	   
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
//--------------------------------------------------------------------------------------panel4
	   PolyPanel.setBackground(Color.blue);
	   
	    frame.getContentPane().add(PolyPanel);

	    JButton button4 = new JButton("Show Poly");
	    
	   
	 
	    PolyPanel.add(button4);
	    	
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	   
	   
	}
			
//----------------------------------------------------------
				public void actionPerformed(ActionEvent evt)
				{
					button1.setText("I've been clicked!");				
					}
			}

  


below the 4th panel i was just trying to get it to say something if you were wondering..


wait so you are saying you think my instructor is asking for me to create a frame for the image to appear in? and the buttons stay there?

[quote name='ryclegman' date='08 April 2010 - 08:10 AM' timestamp='1270743054' post='983621']

View Postryclegman, on 08 April 2010 - 08:03 AM, said:

View PostNeoTifa, on 08 April 2010 - 07:58 AM, said:

You want to change the button into the shape? Why not just draw it in a panel above? So when they click it, just delete the instance of the previous shape and create an instance of the new shape and just call the repaint method. (You need graphics and since I just skimmed I didn't see one).

yes that what i need to do... just draw it in the panel.. where it says show rectangle.. the text would delete and a small rectangle would appear there after they clicked it..

this is what i have so far

import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.awt.*;


public class RAC11_01 implements ActionListener { 
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel RectPanel = new JPanel ();
	   JPanel OvalPanel = new JPanel ();
	   JPanel ArcPanel = new JPanel ();
	   JPanel PolyPanel= new JPanel  ();
		
//----------------------------------------------------------------------	   panel1
	   RectPanel.setBackground(Color.BLACK);
	   frame.getContentPane().add(RectPanel);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	    
	    button1.addActionListener(this);
	    RectPanel.add(button1);
	    
	     frame.setVisible(true);
	     
//---------------------------------------------------------------------------	panel2     
	    
	     OvalPanel.setBackground(Color.red);
		   frame.getContentPane().add(OvalPanel);
		   
		   frame.getContentPane().setLayout(new FlowLayout());
		    frame.setSize(300,150);
		    
		    
		    JButton button2 = new JButton("Show Oval");
		    button2.addActionListener(this);
	
		    OvalPanel.add(button2);
		    
		    
		    frame.setVisible(true);
	     
	     
//--------------------------------------------------------------------------	     panel3
		    ArcPanel.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(ArcPanel);

	    JButton button3 = new JButton("Show Arc");
	   
	   
	 
	    ArcPanel.add(button3);
	   
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
//--------------------------------------------------------------------------------------panel4
	   PolyPanel.setBackground(Color.blue);
	   
	    frame.getContentPane().add(PolyPanel);

	    JButton button4 = new JButton("Show Poly");
	    
	   
	 
	    PolyPanel.add(button4);
	    	
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	   
	   
	}
			
//----------------------------------------------------------
				public void actionPerformed(ActionEvent evt)
				{
					button1.setText("I've been clicked!");				
					}
			}

  


below the 4th panel i was just trying to get it to say something if you were wondering..




ooooooooooooooooooooooo okay i get it.. now just some direct would be nice..
Was This Post Helpful? 0
  • +
  • -

#7 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • Joined: 24-September 08

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:18 AM

Is there no default panel? I'm confused. You are creating panels, making them only to have the button to draw the same shape, yet they don't draw anything. http://java.sun.com/...t/Graphics.html This can maybe help with the Graphics part of it. Just have one panel and draw the 4 buttons at the bottom. Have 4 different listeners going to each, so when one button is clicked, it changes the text on that button and deactivates it, changes the panel's background color, then paints that shape in the middle at the specified x, y coordinate. You're probably going to have to play with it a little.
Was This Post Helpful? 0
  • +
  • -

#8 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:27 AM

View PostNeoTifa, on 08 April 2010 - 08:18 AM, said:

Is there no default panel? I'm confused. You are creating panels, making them only to have the button to draw the same shape, yet they don't draw anything. http://java.sun.com/...t/Graphics.html This can maybe help with the Graphics part of it. Just have one panel and draw the 4 buttons at the bottom. Have 4 different listeners going to each, so when one button is clicked, it changes the text on that button and deactivates it, changes the panel's background color, then paints that shape in the middle at the specified x, y coordinate. You're probably going to have to play with it a little.


okay i am too... this is what he said.. Write a program with four buttons: “Show Rectangle”, “Show Oval”, “Show Arc”, “Show Polygon” When you click a button, a corresponding panel (RectPanel, OvalPanel, ArcPanel and PolyPanel) is shown in the frame.

im not sure if i have to have the button type the name of the button clicked into the default frame for that... or the picture.. i believe just the name..
Was This Post Helpful? 0
  • +
  • -

#9 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • Joined: 24-September 08

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:39 AM

Okay, well create the 4 panels with the shapes and background colors, and have that as a top one. The bottom one can hold the buttons.
Was This Post Helpful? 0
  • +
  • -

#10 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:44 AM

View PostNeoTifa, on 08 April 2010 - 08:39 AM, said:

Okay, well create the 4 panels with the shapes and background colors, and have that as a top one. The bottom one can hold the buttons.


okay well i put each button in its own frame... how to i set panel 5 to say either RectPanel, OvalPanel, ArcPanel and PolyPanel after one of the buttons are clicked? i tried at the bottom but didnt work out..


import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.awt.*;


public class RAC11_01 implements ActionListener { 
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;
	private Object panel5;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel RectPanel = new JPanel ();
	   JPanel OvalPanel = new JPanel ();
	   JPanel ArcPanel = new JPanel ();
	   JPanel PolyPanel= new JPanel  ();
	   JPanel panel5  = new JPanel (); 
//----------------------------------------------------------------------------- FRAME FOR ....
	   
	   panel5.setBackground(Color.PINK);
	   frame.getContentPane().add(panel5);
	   frame.getContentPane () . add (BorderLayout. EAST, panel5);
	    frame.setSize(600,150);
	    
	    
	   
	  
	    
	     frame.setVisible(true);
	     
	   
		
//----------------------------------------------------------------------	   panel1
	   RectPanel.setBackground(Color.BLACK);
	   frame.getContentPane().add(RectPanel);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	   
	    button1.addActionListener(this);
	    RectPanel.add(button1);
	    
	     frame.setVisible(true);
	     
//---------------------------------------------------------------------------	panel2     
	    
	     OvalPanel.setBackground(Color.red);
		   frame.getContentPane().add(OvalPanel);
		   
		   frame.getContentPane().setLayout(new FlowLayout());
		    frame.setSize(300,150);
		    
		    
		    JButton button2 = new JButton("Show Oval");
		    button2.addActionListener(this);
	
		    OvalPanel.add(button2);
		    
		    
		    frame.setVisible(true);
	     
	     
//--------------------------------------------------------------------------	     panel3
		    ArcPanel.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(ArcPanel);

	    JButton button3 = new JButton("Show Arc");
	   
	    button3.addActionListener(this);
	 
	    ArcPanel.add(button3);
	   
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
//--------------------------------------------------------------------------------------panel4
	   PolyPanel.setBackground(Color.blue);
	   
	    frame.getContentPane().add(PolyPanel);

	    JButton button4 = new JButton("Show Poly");
	    
	    button1.addActionListener(this);
	 
	    PolyPanel.add(button4);
	    	
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	   
	   
	}
			
//----------------------------------------------------------
				public void actionPerformed(ActionEvent evt)
				{
					Object source = evt. getSource	();		
					if (source == button1)
					{ panel5.setText="RectPane"}	
					if (source == button2)
					{panel5.setText="OvalPanel"}
					if (source == button3)
					{panel5.setText = "ArcPanel"}
					if (source == button4)
					{panel5.setText="PolyPanel"}
					
				}
			}


   

Was This Post Helpful? 0
  • +
  • -

#11 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • Joined: 24-September 08

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 09:58 AM

When you click the button, just take out the old display panel and add the new one. I would suggest having a BorderLayout manager, with the 4 panels (when activated) in the center, and the button panel in the south.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#12 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 10:03 AM

View Postryclegman, on 08 April 2010 - 08:44 AM, said:

View PostNeoTifa, on 08 April 2010 - 08:39 AM, said:

Okay, well create the 4 panels with the shapes and background colors, and have that as a top one. The bottom one can hold the buttons.


okay well i put each button in its own frame... how to i set panel 5 to say either RectPanel, OvalPanel, ArcPanel and PolyPanel after one of the buttons are clicked? i tried at the bottom but didnt work out..


import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.awt.*;


public class RAC11_01 implements ActionListener { 
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;
	private Object panel5;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RAC11_01 gui = new RAC11_01();
		gui.go();
	}
		
		
public void go(){
	
		
		JFrame frame = new JFrame("Test Frame");
	   JPanel RectPanel = new JPanel ();
	   JPanel OvalPanel = new JPanel ();
	   JPanel ArcPanel = new JPanel ();
	   JPanel PolyPanel= new JPanel  ();
	   JPanel panel5  = new JPanel (); 
//----------------------------------------------------------------------------- FRAME FOR ....
	   
	   panel5.setBackground(Color.PINK);
	   frame.getContentPane().add(panel5);
	   frame.getContentPane () . add (BorderLayout. EAST, panel5);
	    frame.setSize(600,150);
	    
	    
	   
	  
	    
	     frame.setVisible(true);
	     
	   
		
//----------------------------------------------------------------------	   panel1
	   RectPanel.setBackground(Color.BLACK);
	   frame.getContentPane().add(RectPanel);
	   
	   frame.getContentPane().setLayout(new FlowLayout());
	    frame.setSize(300,150);
	    
	    JButton button1 = new JButton("Show Rectangle");
	   
	    button1.addActionListener(this);
	    RectPanel.add(button1);
	    
	     frame.setVisible(true);
	     
//---------------------------------------------------------------------------	panel2     
	    
	     OvalPanel.setBackground(Color.red);
		   frame.getContentPane().add(OvalPanel);
		   
		   frame.getContentPane().setLayout(new FlowLayout());
		    frame.setSize(300,150);
		    
		    
		    JButton button2 = new JButton("Show Oval");
		    button2.addActionListener(this);
	
		    OvalPanel.add(button2);
		    
		    
		    frame.setVisible(true);
	     
	     
//--------------------------------------------------------------------------	     panel3
		    ArcPanel.setBackground(Color.GREEN);
	   
	    frame.getContentPane().add(ArcPanel);

	    JButton button3 = new JButton("Show Arc");
	   
	    button3.addActionListener(this);
	 
	    ArcPanel.add(button3);
	   
	;
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
//--------------------------------------------------------------------------------------panel4
	   PolyPanel.setBackground(Color.blue);
	   
	    frame.getContentPane().add(PolyPanel);

	    JButton button4 = new JButton("Show Poly");
	    
	    button1.addActionListener(this);
	 
	    PolyPanel.add(button4);
	    	
	   frame.setSize(300,150);
	    frame.setVisible(true);
	
	   
	   frame.setDefaultCloseOperation(
	    		JFrame.EXIT_ON_CLOSE);
	   
	   
	   
	}
			
//----------------------------------------------------------
				public void actionPerformed(ActionEvent evt)
				{
					Object source = evt. getSource	();		
					if (source == button1)
					{ panel5.setText="RectPane"}	
					if (source == button2)
					{panel5.setText="OvalPanel"}
					if (source == button3)
					{panel5.setText = "ArcPanel"}
					if (source == button4)
					{panel5.setText="PolyPanel"}
					
				}
			}


   

yes but all i need to do is add a box to take text of what button i picked.. i do not need to use shapes.. only post PectPanel or ovalPanel ect..
Was This Post Helpful? 0
  • +
  • -

#13 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,713
  • Joined: 24-September 08

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 10:25 AM

OOOOOOOOOOOOHHHHHHHHHHHHHHHHHH. JLabel shapeLabel = new JLabel(button.getText());
Was This Post Helpful? 0
  • +
  • -

#14 Guest_ryclegman*


Reputation:

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 10:29 AM

View PostNeoTifa, on 08 April 2010 - 09:25 AM, said:

OOOOOOOOOOOOHHHHHHHHHHHHHHHHHH. JLabel shapeLabel = new JLabel(button.getText());



okay... where does that go exactly
Was This Post Helpful? 0

#15 ryclegman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-February 10

Re: help Displaying shapes after button is clicked

Posted 08 April 2010 - 10:34 AM

where does it go exactly and how do i have it so that once a button is pressed it is written to JLabel shapeLabel = new JLabel(button.getText());
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2