callie's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
11 (0.02 per day)
Joined:
17-November 12
Profile Views:
97
Last Active:
User is offline Nov 25 2012 09:05 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   callie has not set their status

Posts I've Made

  1. In Topic: Move JLabel Task

    Posted 25 Nov 2012

    Hi g00se and pbl,
    Thanks for the feedback. g00se your code worked but I sure don't understand it. I glanced at my friend's text book and about half of what you coded isn't in there....no wonder she failed :( I appreicate the code I will have to study it and look some stuff up so I can get somewhat of a grasp as to what's going on.

    pbl I understand what you are saying , I kind of got that from the text, which is why if I couldn't understand if I put conPanel5.remove(label); didn't work. From what I'm gathering from the text once the Container con = getContentPane(); is added all actions go through the con rather then the JFrame. Am I not understanding correctly?

    Sorry in the delay, lost power for about two hours.
  2. In Topic: Move JLabel Task

    Posted 25 Nov 2012

    PBL and g00se, Thanks for all your help...but I give up. I see now why my friend failed Java(I borrowed her book thinking it can't be that hard) :/ I was doing pretty good til I hit the Swing/GUI chapters. But if I am reading this book correctly, since the Jpanels are in a ContentPane I should still beable to use framePanel5.remove(label) or am I reading this wrong? When I do this it errors out say cannot find symbol, I also tried conPanel5.remove(label) and get the same thing. Guess I should be happy I got as far as I did :tup:
  3. In Topic: Move JLabel Task

    Posted 25 Nov 2012

    Hi gOOse,
    Sorry, I thought I had described my goals. My goal is to have a Jframe with JPanels(I made 6), A JButton that when clicked will move the JLabel around to a new JPanel. I have tried several Layouts, but went with the GridLayout as I can sort of determine where my JPanels are(3 rows,2 colunms). My ultimate goal is to click the button and have the label move to a different panel each time, six panels - six moves. I have tried removing the label from one panel and adding to another, setBounds(of which now my label disappears), setLocation(which seemed to just move the label to a different location within the panel it's in).
  4. In Topic: Move JLabel Task

    Posted 25 Nov 2012

    OK, I'm still not getting this.... When I setBounds() my JLabel just disappears. I think I may not be setting bounds correctly. I even tried to set the JLabel setVisible(true) after JButton is clicked. I thought maybe the JLabel was being positioned under the JPanel.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JMovingFrame extends JFrame implements ActionListener
    {
    	private final int WIDTH = 350;
    	private final int HEIGHT = 400;
       JButton button = new JButton("Please click ");
    	private int numClicks = 0;
    	JLabel label = new JLabel("Smile ");
    	public JMovingFrame()
    	 {
    	  super("J Moving Frame ");
    	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	  JPanel panel1 = new JPanel();
    	  JPanel panel2 = new JPanel();
    	  JPanel panel3 = new JPanel();
    	  JPanel panel4 = new JPanel();
    	  JPanel panel5 = new JPanel();
    	  JPanel panel6 = new JPanel();
    	  Container con = getContentPane();
    	  con.setLayout(new GridLayout(3,2,2,4));
    	  con.add(panel1);
    	  con.add(panel2);
    	  con.add(panel3);
    	  con.add(panel4);
    	  con.add(panel5);
    	  con.add(panel6);
    	  panel6.add(button);
    	  button.setLocation(340, 380);
    	  button.addActionListener(this);
    	  button.setToolTipText("Click this button ");
    	  panel5.add(label);
    	  label.setLayout(null);
    	  setSize(WIDTH, HEIGHT);
    	 }
    	public void actionPerformed(ActionEvent e)
    	  {
    	  label.setBounds(100, 300, 150, 50);
    	  label.setVisible(true);
    	  }	
    	public static void main(String[] args)
    	 {
    	  JMovingFrame frame = new JMovingFrame();
    	  frame.setVisible(true);
    	 } 
    }
    
    
    
    
  5. In Topic: Move JLabel Task

    Posted 24 Nov 2012

    I see now that programming is not my strong point. PBL, I tried to figure out the GridBagLayout and was so lost..... I finally went with the GridLayout as I can kind of determine where my JPanels are. But everything I try to put in to move the JLabel doesn't work. It does move but not to a new panel. It seems as if it's just moving around the one JPanel :( Is this what you meant by most other layouts ignore specified position. Is it possible that I need to set the layout to the Jpanels rather then the container? Any suggestions would be greatly appreciated.

    import java.awt.*;
    import java.awt.event.*;
    public class JMovingFrame extends JFrame implements ActionListener
    {
    	private final int WIDTH = 350;
    	private final int HEIGHT = 400;
            JButton button = new JButton("Please click ");
    	JLabel label = new JLabel("Smile ");
    	public JMovingFrame()
    	 {
    	  super("J Moving Frame ");
    	  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	  JPanel panel1 = new JPanel();
    	  JPanel panel2 = new JPanel();
    	  JPanel panel3 = new JPanel();
    	  JPanel panel4 = new JPanel();
    	  JPanel panel5 = new JPanel();
    	  JPanel panel6 = new JPanel();
    	  Container con = getContentPane();
    	  con.setLayout(new GridLayout(3,2,2,4));
    	  con.add(panel1);
    	  con.add(panel2);
    	  con.add(panel3);
    	  con.add(panel4);
    	  con.add(panel5); con.add(panel6);
    	  panel6.add(button);
    	  button.setLocation(340, 380);
    	  button.addActionListener(this);
    	  button.setToolTipText("Click this button ");
    	  panel5.add(label);
    	  setSize(WIDTH, HEIGHT);
    	 }
    	public void actionPerformed(ActionEvent e)
    	  {
    	  label.setLocation(20, 10);
    	  }	
    	public static void main(String[] args)
    	 {
    	  JMovingFrame frame = new JMovingFrame();
    	  frame.setVisible(true);
    	 } 
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

callie hasn't added any friends yet.

Comments

callie has no profile comments yet. Why not say hello?