Answer to Question #4503 in AJAX | JavaScript | HTML | PHP for trudence

Question #4503
what are JPanels and how do they work?
1
Expert's answer
2011-10-11T08:00:18-0400
JPanel is a public java swing class which is used to create a general-purpose container JPanel objects that are used to group other GUI components without adding any functionality to the added components.

JPanel panel objects can add color to their background and also can be customized. JPanel inherits methods from it’s super classes namely JComponent, Container, and Component java classes. JPanel is an extension of java swing JComponent class. JPanel class implements Accessible interface.

Following is a list of constructors of JPanel Class:-

* JPanel() which creates a new JPanel panel object with a double buffer and a default flow layout
* JPanel(boolean isDoubleBuffered)which creates a new JPanel panel object with FlowLayout and the buffering strategy as specified.
* JPanel(LayoutManager layout) which creates a new buffered JPanel panel object with the specified layout manager
* JPanel(LayoutManager layout, boolean isDoubleBuffered) which creates a new JPanel with the specified layout manager and specified buffering strategy.

Underneath is an example of java code, JpanelExample.java, which demonstrate use of JPanel in a simple GUI java program.

import javax.swing.*;
import java.awt.*;
&
public class JPanelExample {
&
& public static void main(String[] args) {
JFrame frame1=new JFrame("Creating a Jframe and using JPanel JComponent");
frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
frame1.setSize(400,200);

Container c=new JPanel();
c.add(new JButton("First Button"));
c.add(new JButton("Second Button"));
c.add(new JButton("Third Button"));

frame1.getContentPane().add(c);

frame1.show();

& }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS