Posted By

DrPepper on 02/09/11


Tagged


Versions (?)

[JAVA] CH9 Show the System clock


 / Published in: Java
 

Using Date function and get a system clock me and my friend are editing this code last update was also working, I just followed the text book and made it. new one will be his professor preferring that way.

  1. //import javax.swing.JFrame;
  2. import javax.swing.JComponent;
  3. import java.util.*;
  4. import java.awt.*;
  5. import java.awt.geom.Ellipse2D;
  6. /**
  7.   main function
  8.   */
  9. public class ellipse extends JComponent
  10. {
  11. private double xpos;
  12. private double ypos;
  13. private double width;
  14. private double height;
  15.  
  16. public ellipse(float x, float y, float w, float h){
  17. xpos = x;
  18. ypos = x;
  19. width = x;
  20. height = x;
  21. }
  22.  
  23. public void painting(Graphics2D g2, double x, double y, double w, double h)
  24. {
  25. //super.paintComponent(g2);
  26. Ellipse2D.Double circle = new Ellipse2D.Double(x,y,w,h);
  27. g2.setColor(Color.BLUE);
  28. g2.fill(circle);
  29.  
  30. Date now = new Date();
  31. g2.setColor(Color.BLACK);
  32. g2.drawString(" "+now,270,450);
  33.  
  34. }
  35. public void paint(Graphics g)
  36. {
  37. this.painting(g2, xpos, ypos, width, height);
  38. }
  39. }
  40.  
  41.  
  42. /**
  43.   time.java
  44. */
  45.  
  46. /**
  47.   Write a program that uses a timer to print the current time once a second
  48.   Hint : The following coe prints the current time :
  49.   Data naw = new Date();
  50.   System.out.println(now);
  51.   The Data class is in the java util package.
  52. */
  53.  
  54. import javax.swing.JFrame;
  55. public class time extends JFrame
  56. {
  57.  
  58. public static void main(String [] args)
  59. {
  60. JFrame frame = new JFrame();
  61. //viewer t = new viewer();
  62. ellipse t = new ellipse(30, 40, 300, 100);
  63. frame.setSize(500,500);
  64. frame.setTitle("*** Blablabla ***");
  65. frame.add(t);
  66. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67. frame.setVisible(true);
  68.  
  69. }
  70.  
  71. }

Report this snippet  

You need to login to post a comment.