answersLogoWhite

0


Best Answer

I never tried this, but it should work if you get the event source and cast it to a JPanel object. This is what it should look like:

JPanel newPanel = (JPanel) event.getSource();

What you did is assign the reference of the source panel to a new panel, and now you can go on with your code.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you identify which JPanel type panel caused the event in Java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explain the usage of JPanel with example?

JPanel, a part of Java Swing package, is a container that can store a group of components. The main task of JPanel is to organize components, various layouts can be set in JPanel which provide better organization of components, and however it does not have a title bar. For Example: Program to create a JPanel with a Border layout and add components to it . // java Program to create a JPanel with a Border layout and add components to it . import java.awt.event.; import java.awt.; import javax.swing.*; class solution extends JFrame { // JFrame static JFrame f; // JButton static JButton b, b1, b2, b3; // label to diaplay text static JLabel l; // main class public static void main(String[] args) { // create a new frame to stor text field and button f = new JFrame("panel"); // create a label to display text l = new JLabel("panel label"); // create a new buttons b = new JButton("button1"); b1 = new JButton("button2"); b2 = new JButton("button3"); b3 = new JButton("button4"); // create a panel to add buttons and a specific layout JPanel p = new JPanel(new BorderLayout()); // add buttons and textfield to panel p.add(b, BorderLayout.NORTH); p.add(b1, BorderLayout.SOUTH); p.add(b2, BorderLayout.EAST); p.add(b3, BorderLayout.WEST); p.add(l, BorderLayout.CENTER); // setbackground of panel p.setBackground(Color.red); // add panel to frame f.add(p); // set the size of frame f.setSize(300, 300); f.show(); } }


What steps does a supervisor follow to develop a screening panel to screen candiddates?

Identify number on screening panel, select members with a range of experience and background to maximize fairness; appoint leader


Where is the instrument panel on a Ford Explorer?

Above the steering wheel. Most people can identify the instrument panel by the speedometer in the middle.


What actions can supervisors exercise to prevent the common error of waiting for a referral list before beginning to develop a plan of employee selection?

Identify selection panel, compile screening matrix, and create an interviewing plan


Where would personnel place a VS-17 signal panel to identify troops?

On the ground


Java program code for student Information?

import javax.swing.*; import java.awt.*; import java.awt.event.*; class jwp extends JFrame implements ActionListener{ JButton button = new JButton ("Submit"); JTextField field = new JTextField(); JLabel label = new JLabel("Enter your name : ",Label.RIGHT); public jwp(){ super("JFrame with panel and button"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(null); panel.add(label); panel.add(field); panel.add(button); setContentPane(panel); button.setBounds(100,70,100,50); label.setBounds(20,30,200,20); field.setBounds(120,30,100,20); button.addActionListener(this);} public void actionPerformed (ActionEvent e){ if (e.getSource() ==button){ JOptionPane.showMessageDialog(this,"Youre name was "+field.getText());} } } public class frame1 { public static void main (String[] args) { jwp start = new jwp(); start.setSize(300, 200); start.setVisible(true); } } that's alll.......i can't upgrade it anymore......


Judging by its location in control panel what type of tool is event viewers?

The Event Viewer is reached in Administrative Tools, which is listed in System Maintenance.


Which is the only panel on the Baptistery doors to represent a single event?

meeting of Solomon and Sheba


How to Identify fuses in Saturn Wagon?

I thought the fuse diagram was on the back side of the fuse panel cover.


What steps does a supervisor follow to develope a screening panel to screen candidates?

Identify number on screening panel, select members with a range of experience and background to maximize fairness; appoint leader


What steps does a supervisor follows to develop a screening panel to screen candidates?

Identify number on screening panel, select members with a range of experience and background to maximize fairness; appoint leader


What steps does a supervisor follow to development a screen panel to screen candidates?

Identify number on screening panel, select members with a range of experience and background to maximize fairness; appoint leader