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

Question #4503
what are JPanels and how do they work?
Expert's answer
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,, 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");

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


& }

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!


No comments. Be the first!

Leave a comment

Ask Your question

New on Blog