4 problems to solve - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

4 problems to solve

Description:

4 problems to solve. Formatting a Date( ) for Month, Year only ... import java.util.Date; public class test. public test ... Date myDate = new Date ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 7
Provided by: msresearch
Category:
Tags: date | problems | solve

less

Transcript and Presenter's Notes

Title: 4 problems to solve


1
4 problems to solve
  • Formatting a Date( ) for Month, Year only
  • Forcing button layout on a JFrame (when the
    layout manager is no help)
  • Determining which component caused an event
  • JButton Colors

2
import java.util.Date public class testpublic
test() System.out.println("Starting
test program") Date myDate new Date()
System.out.println( myDate ) public
static void main(String args ) test app
new test( )
3
DateFormat class
  • import java.util. // for Date
  • import java.text. // for DateFormat
  • public class shortDate
  • public static void main(String args)
  • Date myDate new Date()
  • DateFormat df DateFormat.getDateInstance()
  • String todaysDate df.format( myDate )
  • System.out.println( todaysDate )

4
Sub-layouts
  • Add buttons to a JPanel
  • JButton exitButton new JButton(Exit)
  • JPanel topRow new JPanel()
  • topRow.add( exitbutton )
  • Add JPanel to the container
  • c.add( topRow )

5
e.getSource
  • e.getActionCommand gets the button label
  • What if the event is caused by a component that
    has no label (like a Timer)?
  • e.getSource( ) returns the component object
  • So all components must be public.

6
JButton Colors
  • JButton exitButton new JButton(Exit)
  • exitButton.setBackground( Color.red )
Write a Comment
User Comments (0)
About PowerShow.com