Results 1 to 7 of 7
Thread: When I create method...
- 05-12-2010, 02:11 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 19
- Rep Power
- 0
When I create method...
Can you find the bug in this code?
Is there a problem, the way I created "showDialogBox()" method?Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication61; import javax.swing.*; import java.awt.event.*; public class ShowDialogBox { JFrame frame; public static void main(String[] args) { ShowDialogBox db = new ShowDialogBox(); // TODO code application logic here } [B] public showDialogBox(){[/B] frame = new JFrame("Show Her"); JButton button = new JButton("Click Me"); button.addActionListener(new MyAction()); frame.add(button); frame.setSize(200,200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public class MyAction implements ActionListener{ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(frame,"Leann is suckz!"); } } }
-
It's not a method, it's a constructor, and constructor names have to match class names exactly, including spelling and cApItAlIzAtIoN.
- 05-12-2010, 02:22 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 19
- Rep Power
- 0
-
- 05-12-2010, 06:45 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
I always wonder why people leave that generated comment in as it is ...Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */
kind regards,
Jos ;-)
- 05-12-2010, 12:06 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
<shuffle, shuffle>...:)
- 05-13-2010, 09:42 PM #7
try this
Java Code:package javaapplication61; import javax.swing.*; import java.awt.event.*; public class ShowDialogBox { JFrame frame; public static void main(String[] args) { ShowDialogBox db = new ShowDialogBox(); // TODO code application logic here } public ShowDialogBox() { frame = new JFrame("Show Her"); JButton button = new JButton("Click Me"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(frame, "Leann is suckz!"); } }); frame.add(button); frame.setSize(200, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 07:20 PM -
Create code for Binary Search Tree using compareTo method using I/O
By harvin23 in forum New To JavaReplies: 5Last Post: 10-13-2009, 01:35 PM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks