• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java Swing ActionPerformed method why static context?

 
Ranch Hand
Posts: 103
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I try to convert date from String in this method, but become an error about static context.
Why this happens?
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would I be correct that "DateFormat" is the name of a class and not the name of a variable? Because you should have a variable of type DateFormat in that location.
 
Mike Savvy
Ranch Hand
Posts: 103
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Would I be correct that "DateFormat" is the name of a class and not the name of a variable? Because you should have a variable of type DateFormat in that location.


Hello Paul, this is a class java.text.DateFormat.
But I used also other classes like java.util.GregorianCalendar and have same problem
 
Paul Clapham
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. If you want to use a method of class X, and it's not a static method, you need an object of type X to call that method with.

Example: DateFormat and SimpleDateFormat Examples.
 
Mike Savvy
Ranch Hand
Posts: 103
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Yup. If you want to use a method of class X, and it's not a static method, you need an object of type X to call that method with.

Example: DateFormat and SimpleDateFormat Examples.



Sure, thank you very much!
 
Marshal
Posts: 69896
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why are you using Date? Has nobody told you how bad it is as class design? And Calendar is hardly better. We should all be using the java.time package
 
Mike Savvy
Ranch Hand
Posts: 103
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I use GregorianCalendar. Date class was just for testing the problem
 
Campbell Ritchie
Marshal
Posts: 69896
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GregorianCalendar is simply a subtype of Calendar.
    Bookmark Topic Watch Topic
  • New Topic