Creating first GUI Java Program

Reply

Join Date: Jan 2005
Posts: 31
Reputation: AQWst is an unknown quantity at this point 
Solved Threads: 0
AQWst AQWst is offline Offline
Light Poster

Creating first GUI Java Program

 
0
  #1
Feb 19th, 2005
I am new to GUI Java programming and I am attempting to find the best way of creating a frame to contain a series of menus. I am first adding logic to have the date and time appear in the frame, but the way I am doing it they are both showing up on the same line and I can't seem to find any sources on how to get these and additional text to appear on separate lines. I will include my source to have someone look at it or tear it apart. May I ask that some one please point me in the right direction to a source to this type of programming or offer me some advice on a better method of doing this simple task?
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class InitialFrame1 extends JFrame
  7. {
  8. public InitialFrame1()
  9. {
  10. setSize(800, 625);
  11. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12. Container pane = getContentPane();
  13. FlowLayout flo = new FlowLayout();
  14. pane.setLayout(flo);
  15. InitialPanel Date = new InitialPanel();
  16. pane.add(Date);
  17. setContentPane(Date);
  18. InitialPanel Time = new InitialPanel();
  19. pane.add(Time);
  20. setContentPane(Time);
  21. setVisible(true);
  22. }
  23.  
  24. public static void main (String[] arguments)
  25. {
  26. InitialFrame1 a1 = new InitialFrame1();
  27. }
  28.  
  29. public class InitialPanel extends JPanel
  30. {
  31. public InitialPanel()
  32. {
  33. String Current_Date = getDate();
  34. JLabel Date = new JLabel(Current_Date);
  35. Date.setForeground(Color.blue);
  36. add(Date);
  37. String Current_Time = getTime();
  38. JLabel Time = new JLabel(Current_Time);
  39. Time.setForeground(Color.blue);
  40. add(Time);
  41.  
  42. }
  43.  
  44. String getDate()
  45. {
  46. String Date;
  47. // get current Date
  48. Calendar now = Calendar.getInstance();
  49. int month = now.get(Calendar.MONTH) + 1;
  50. int day = now.get(Calendar.DAY_OF_MONTH);
  51. int year = now.get(Calendar.YEAR);
  52.  
  53. Date = month + "/" + day + "/" + year;
  54. return Date;
  55. }
  56.  
  57. String getTime()
  58. {
  59. String Time;
  60. // get current Time
  61. Calendar now = Calendar.getInstance();
  62. int hour = now.get(Calendar.HOUR_OF_DAY);
  63. int minute = now.get(Calendar.MINUTE);
  64. int second = now.get(Calendar.SECOND);
  65.  
  66. Time = hour + ":" + minute + ":" + second;
  67. return Time;
  68. }
  69.  
  70. }
  71. }
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 8
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Creating first GUI Java Program

 
0
  #2
Feb 19th, 2005
pane.getContentPane().add(Date, flo.TOP); // can be TOP, RIGHT, BOTTOM, LEFT
pane.getContentPane().add(Time, flo.BOTTOM); // can be TOP, RIGHT, BOTTOM, LEFT

Heres the java documentation for JFrame: http://java.sun.com/j2se/1.4.2/docs/...ng/JFrame.html
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Creating first GUI Java Program

 
0
  #3
Feb 19th, 2005
Use BorderLayout, not FlowLayout, for your main frame.
Then put the menu in TOP and the main content in CENTER (in which you may have to add JPanels with their own layout managers to get the effect you want).
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 4
Reputation: sandesh_daddi is an unknown quantity at this point 
Solved Threads: 0
sandesh_daddi sandesh_daddi is offline Offline
Newbie Poster

Help Friend

 
0
  #4
Feb 19th, 2005
hi friend i am not telling to how to code in java because i m also new to java i am doing my MCA in pune (INDIA) in FIRST SEM i m ne wto this programming




i want to know that how to post my quries to every one i read that select forum and click new thread button but i can't saw :cry: any such button

so please HELP ME

we have projrcts in JAVA if u know any project title please tell me it will only for 50 marks and without data base .

plz HELP MI
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Creating first GUI Java Program

 
0
  #5
Feb 19th, 2005
You should post a seperate thread, so that you don't distract away from this thread starter.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 35
Reputation: tigerxx is an unknown quantity at this point 
Solved Threads: 0
tigerxx tigerxx is offline Offline
Light Poster

Re: Help Friend

 
0
  #6
Feb 23rd, 2005
Originally Posted by sandesh_daddi
hi friend i am not telling to how to code in java because i m also new to java i am doing my MCA in pune (INDIA) in FIRST SEM i m ne wto this programming




i want to know that how to post my quries to every one i read that select forum and click new thread button but i can't saw :cry: any such button

so please HELP ME

we have projrcts in JAVA if u know any project title please tell me it will only for 50 marks and without data base .

plz HELP MI

u can go for a image processing in java

can go in GUI manner
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 13
Reputation: shinnxennosagga is an unknown quantity at this point 
Solved Threads: 1
shinnxennosagga shinnxennosagga is offline Offline
Newbie Poster

Re: Creating first GUI Java Program

 
0
  #7
Mar 8th, 2008
I' not sure guys, but I don't think there's TOP or BOTTOM constant in FlowLayout or BorderLayout, for FlowLayout, there're only LEFT, RIGHT, and CENTER. For BorderLayout, there're CENTER, SOUTH, NORTH, WEST, and EAST.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 787
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Creating first GUI Java Program

 
0
  #8
Mar 8th, 2008
Hi there shinnxennosagga,

Please check the date of threads before posting a reply to them - you have just resurrected a thread that hasn't been used for three years...
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Creating first GUI Java Program

 
1
  #9
Mar 8th, 2008
and giving an answer that's incorrect too...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: gap_89 is an unknown quantity at this point 
Solved Threads: 0
gap_89 gap_89 is offline Offline
Newbie Poster
 
0
  #10
12 Days Ago
hey can u help me by dis problem
write down an application to display a window with various GUI components available in the awt packages
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC