• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wats the prob?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class test1 implements ActionListener
{
JButton b;

test1(){
super(new BorderLayout());
b=new JButton("Click Me");;
b.setLayout(new BorderLayout());
b.setPreferredSize(new Dimension(200,80));
add(b, BorderLayout.CENTER);
b.addActionListener(this);
}

public void actionPerformed (ActionEvent e){
System.out.println("Button is clicked");
}

private static void createAndShowGUI(){
JFrame f = new JFrame("Hello");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}

public static void main(String[] args) {
createAndShowGUI();
}


plz help..
thanks in advance
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a gander at How To Ask Questions The Smart Way and see if you can't ask a better question than "wats the prob".
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe's right: asking a good question usually helps a lot. But this program is so broken, several things jump out on even a casual glance. For example although JButtons do have a "setLayout" method, it's only as an unintended side effect of their inheritance; you shouldn't use it. Your class "test1" extends Object, and Object has no constructor that takes a LayoutManager, so the super(new BorderLayout()) won't even compile. I'm assuming you want to construct a JFrame with a BorderLayout, but not even JFrame has such a constructor -- you have to use setLayout() on the JFrame. Finally, in your main(), you don't create a test1 object anywhere, but you do create an empty JFrame and show it, so your button won't be in evidence.

So that's the prob.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic