Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2004, 06:33 AM
Registered User
 
Join Date: Jun 2004
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();
        }
    }
}






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.