Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 9th, 2004, 06:33 AM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default layout

Hi, this is probably fairly simple but im only just beginning to program graphics in java. What I need is for the setPanel, which holds the setClockButton, to be underneath what the paint method produces. Anyone now how I can achieve this.

import java.awt.*;
import java.awt.event.*;
public class DisplayClockTime extends Panel implements ActionListener
{
    private static int r = 65;
    private int x = 150;
    private int y = 150;
    private int minX, minY, hourX, hourY;
    private boolean timeSet;
    private Label hourLabel = new Label("Hour");
    private TextField hourField = new TextField(2);
    private Label minsLabel = new Label("Mins");
    private TextField minsField = new TextField(2);
    private Button setClockButton = new Button("Set clock");
    public Panel holdAll = new Panel();
    private Panel timePanel = new Panel();
    private Panel setPanel = new Panel();

    public DisplayClockTime(){
        holdAll.setLayout(new BorderLayout());

        timePanel.add(hourLabel);
        timePanel.add(hourField);
        timePanel.add(minsLabel);
        timePanel.add(minsField);

        setPanel.add(setClockButton);

        holdAll.add("North",timePanel);
        holdAll.add("South",setPanel);

        add(holdAll);
        timeSet = false;

        hourField.addActionListener(this);
        minsField.addActionListener(this);
        setClockButton.addActionListener(this);
    }

    public void paint(Graphics g){
        g.drawOval(85,85,2*r,2*r);
        if(timeSet == true){
            g.setColor(Color.blue);
            g.drawLine(x,y,minX,minY);
            g.drawLine(x,y,hourX,hourY);
        }
    }



    public void actionPerformed(ActionEvent e){
        String hourEntered = hourField.getText();
        String minsEntered = minsField.getText();
        int minsIn, hourIn;
        double theta;

        if(e.getSource() == setClockButton){
            minsIn = (int)Double.parseDouble(minsEntered);
            hourIn = (int)Double.parseDouble(hourEntered);

            theta = 2 * Math.PI * minsIn/60;
            minX = x + (int)(r * 0.9 * Math.sin(theta));
            minY = y - (int)(r * 0.9 * Math.cos(theta));

            theta = 2 * Math.PI * (hourIn + minsIn/60.0)/12.0;
            hourX = x + (int)(r * 0.65 * Math.sin(theta));
            hourY = y - (int)(r * 0.65 * Math.cos(theta));

            timeSet = true;
            repaint();
        }
    }
}

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 column layout acevision7 BOOK: Professional CSS: Cascading Style Sheets for Web Design 0 February 24th, 2008 11:13 PM
CSS Layout DeadMeatGF CSS Cascading Style Sheets 2 November 5th, 2005 03:23 PM
3 Row Layout simrud CSS Cascading Style Sheets 3 August 1st, 2005 06:47 PM
Datalist layout silverfox_1188 ASP.NET 1.0 and 1.1 Professional 2 May 13th, 2005 05:43 AM
datalist layout silverfox_1188 Classic ASP Components 0 May 11th, 2005 04:16 PM



All times are GMT -4. The time now is 06:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.