Hi there,
Every time i am making a program in Java(Advance). I found that it can many errors in it.
For example I am Giving u a program written by me


//a push button with all features

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

class Mybuttons1 extends Frame
{
//vars 
JButton b;
//constructor
Mybuttons1()
{
//goto content pane
Container c = this.getContentPane();
//set the flow layout to c
c.setLayout(new FlowLayout());
//load the image into ImageIcon class object

ImageIcon obj;
ImageIcon ii = new ImageIcon("India_by_mr_curry.jpg");
//create the button with image on it
b = new JButton("Click Me",ii);
//set colors
b.setBackground(Color.yellow);
b.setForeground(Color.red);
//set a font
Font f = new Font("Arial",Font.BOLD,32);
b.setFont(f); 
//set bevel border
//Border bd = BorderFactory.createBevelBoreder(BevelBorder.RAISED);
b.setBorder(bd);
//set a tool tip text
b.setToolTipText("I am Button");
//set a  short cut key
//b.setMneomnic('C');
//add button to C
c.add(b);
//close the application
this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
}

public static void main(String a[])
{
//create the frame
Mybuttons1 mb = new Mybuttons1();
mb.setTitle("My Push Button");
mb.setSize(400,300);
mb.setVisible(true);
}
}

After compiling it I am getting three errors can....Your reply will be appreciated

Edited 5 Years Ago by __avd: Added [code] tags.

Okay? Nobody writes error free programs in a first draft (or even 100th, many times), so what's the problem?

In this program the error is "cannot find symbol in
Container c = this.getContentPane(); method,
same error in
b.setBorder(bd);

also in
this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );

this is error i am getting and I am unable to rum my program

1-- > Extend your class with JFrame (not with Frame)
2-- > Uncomment //Border bd = BorderFactory.createBevelBoreder(BevelBorder.RAISED);
and replace Border bd = BorderFactory.createBevelBoreder(BevelBorder.RAISED); with Border bd = BorderFactory.createBevelBorder(BevelBorder.RAISED);
then run ur app

Thanks alot ....its working Fine now....there are some other question which i want to ask..there is another program in which i have created there is one error...
non static method get content pane cannot be referenced from a static context
Container content = getContentPane();

this is the source code

import java.awt.*;
import javax.swing.*;

class HelloWorld extends JFrame
{
public static void main(String args[])
{
HelloWorld hw = new HelloWorld();

JLabel jl = new JLabel("Hello World");
hw.add(jl);
hw.setSize(100, 100);

hw.setVisible(true);
hw.setTitle("My Message to the JFrame");
hw.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );


Container content = getContentPane();
    content.setBackground(Color.white);
    content.setLayout(new FlowLayout());
    JButton button1 = new JButton("Java");
    content.add(button1);
    ImageIcon cup = new ImageIcon("images/cup.gif");
    JButton button2 = new JButton(cup);
    content.add(button2);
    JButton button3 = new JButton("Java", cup);
    content.add(button3);
    JButton button4 = new JButton("Java", cup);
    button4.setHorizontalTextPosition(SwingConstants.LEFT);
    content.add(button4);
    
    button4.setVisible(true);

}
}

this is the problem i faced earlier also. So can u tell me what is the bug in brief, and what mistake i am doing...

Edited 5 Years Ago by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

Something like this:

class Main {
    public static void main(String args[]) {
        new Main();
    }
    Main() {
        //place JFrame logic here
    }
}
This article has been dead for over six months. Start a new discussion instead.