Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 24th, 2006, 09:13 PM
a4avaiz a4avaiz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 2 a4avaiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 22 sec
Reputation Power: 0
Newbie Question Regarding Layouts

Hi. I am brand new to Java. This is a very basic question.

I have been playing around with layouts. I started off with the FlowLayout. Basically, I wanted a layout with buttons, text fields and few regular shapes.

I was able to come with the previous two, but when i draw shapes, the buttons and text boxes dissappear.

I am using the paint(Graphics g) to draw these shapes. Is there a possibility to show both controls and graphics on the container?.

If not, is it also possible to display the buttons on one window and the shapes on another?.

Thanks in advance!

Reply With Quote
  #2  
Old July 25th, 2006, 09:50 AM
a4avaiz a4avaiz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 2 a4avaiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 22 sec
Reputation Power: 0
no one?

Reply With Quote
  #3  
Old July 27th, 2006, 10:24 PM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 12
I'm guessing you probably forgot to overide paincomponent.
Here's a piece of one of my codes, not the best solution, but I hope it helps.

This is after creating texfields and buttons: It does it all on the same window without you needing to specify that.
Code:
  public void paintComponent(Graphics g)
      {
         super.paintComponent (g);
         
         X=-500; 																	  //X=-500 is Xmin
      	      
         g.setColor (Color.white);                                  //sets color of graphs background
         g.fillRect (0,55,size,size);                               //draws the graph area background
			
         g.setColor (Color.black);                                  //sets color of axis
         g.drawLine (size/2,55,size/2,size+55);                     //draws vertical axis
         g.drawLine (0,((size+50)/2)+100,size,((size+50)/2)+100);   //draws horizontal axis
                					
         while (X<500)                                               //X=500 is Xmax
         {
             	             
            Y = A*Math.pow(X,3) + B*Math.pow(X,2) + C*X + D;         //AX^3 + BX^2 + CX + D
            
				g.setColor (Color.red);                                  //sets color of the graph
            int Y2 = (int)Y;
            int X2 = (int)X;                                         //X and Y must be integers to fit in drawline command.
				
            X=X+0.01;                                                //
            //System.out.println (X2+" , "+Y2);                      //may be used to optionally dysplay values for X and Y
            
            g.drawLine ((Y2+(size/2)),(X2+((size+50)/2)+100),(Y2+(size/2)),X2+((size+50)/2)+100); 
                                                                     //draws the graph
          }
      }
       
       private class PlotterAdapter implements ActionListener
      {
          public void actionPerformed (ActionEvent event)
         {
            String text1 = input1.getText();                         //gets a string from user
            String text2 = input2.getText();                         //
            String text3 = input3.getText();                         //
            String text4 = input4.getText();                         //gets a string from user
				
            A = Double.parseDouble (text1);                          //converts string to Double
        		B = Double.parseDouble (text2);                          //
            C = Double.parseDouble (text3);                          //
            D = Double.parseDouble (text4);                          //converts string to Double
				
				repaint();                                               //redraws the graph when button is pressed
         }
      }

oh and don't forget the repaint at the very bottom, really important.

Reply With Quote
  #4  
Old September 12th, 2006, 02:21 AM
arunsudhir arunsudhir is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 4 arunsudhir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 33 sec
Reputation Power: 0
can you post your code??? so that we can understand what is excatly your problem... as you are a newbie.. you might be doing some simple things wrong... there is nothing that stops you from dispalying graphics along with GUI... but put the graphics in a separate panel and attach it to the Frame's content pane...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Newbie Question Regarding Layouts


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap