W2R1 – Add an ActionListener

This commit is contained in:
bobbert committed 2025-02-04 17:55:53 +00:00
1 parent 428343eb35
commit 7b81ac78e2
1 file changed
+24 -8
@@ -7,6 +7,7 @@ package userprofilebuilder.view;
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.JFrame; import javax.swing.JFrame;
import java.awt.event.*;
/** /**
* *
@@ -22,22 +23,37 @@ public class MainViewer {
{ {
count++; int row = count+1;
String name = "Name"; String name = "Name";
JRadioButton JR = new JRadioButton(name); // temporary use of name as label for JRadioButton - to allow for the use of text being manipulated // changed. JRadioButton JR = new JRadioButton(name); // temporary use of name as label for JRadioButton - to allow for the use of text being manipulated // changed.
JButton JB1 = new JButton("Edit"); JButton JEdit = new JButton("Edit");
JButton JB2 = new JButton("Delete"); JButton JDelete = new JButton("Delete");
jp.add(JR); jp.add(JR);
jp.add(JB1); jp.add(JEdit);
jp.add(JB2); jp.add(JDelete);
System.out.println("Row number: "+ count + " Has been created!"); System.out.println("Row number: "+ row + " Has been created!");
ActionListener buttonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Edit Button clicked for Row: " + row + "with Radio Button Text as: " + JR.getText());
}
};
JEdit.addActionListener(buttonListener);
} }
public void DialogueBox(){
}
public void TabMaker(String Pname, JTabbedPane JT) public void TabMaker(String Pname, JTabbedPane JT)
{ {
@@ -66,9 +82,9 @@ public class MainViewer {
JTabbedPane JT = new JTabbedPane(); JTabbedPane JT = new JTabbedPane();
TabMaker("User Title", JT);
TabMaker("User Name", JT); TabMaker("User Name", JT);
TabMaker("Test1", JT); TabMaker("User Email", JT);
TabMaker("Tab2", JT);
viewer.add(JT); viewer.add(JT);
JT.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); JT.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);