/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle or the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

//package components;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

/*
* ButtonDemo.java requires the following files:
* images/right.gif
* images/middle.gif
* images/left.gif
*/
public class ButtonDemo extends JPanel
implements ActionListener {
protected JButton b1, b2, b3, b4;

public ButtonDemo() {
ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

b1 = new JButton("Axxxxxx"/*, leftButtonIcon*/);
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
b1.setMnemonic(KeyEvent.VK_D);
b1.setActionCommand("enableb1");
b1.setEnabled(true);

b2 = new JButton("Bxxxxxxx"/*, middleButtonIcon*/);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b2.setActionCommand("enableb2");
b2.setEnabled(true);

b3 = new JButton("Cxxxxxxx"/*, rightButtonIcon*/);
//Use the default text position of CENTER, TRAILING (RIGHT).
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enableb3");
b3.setEnabled(true);

b4 = new JButton("Dxxxxxxx"/*, rightButtonIcon*/); // copied from b3
//Use the default text position of CENTER, TRAILING (RIGHT).
b4.setMnemonic(KeyEvent.VK_S);
b4.setActionCommand("enableb4");
b4.setEnabled(true);

//Listen for actions on all buttons.
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

b1.setToolTipText("Click for a UPNs");
b2.setToolTipText("Click for b UPNs");
b3.setToolTipText("Click for c UPNs");
b4.setToolTipText("Click for d UPNs");

JLabel labelUpn = new JLabel("UPN number here on button press");

//Add Components to this container, using the default FlowLayout.
add(b1);
add(b2);
add(b3);
add(b4);
add(labelUpn);
labelUpn.setText("UPN number here");
}

public void actionPerformed(ActionEvent e) {
if ("enableb1".equals(e.getActionCommand())) {
b1.setEnabled(false);
b2.setEnabled(true);
b3.setEnabled(true);
b4.setEnabled(true);
b1.setText("B1 Pressed");
} else if ("enableb2".equals(e.getActionCommand())) {
b1.setEnabled(true);
b2.setEnabled(false);
b3.setEnabled(true);
b4.setEnabled(true);
b2.setText("B2 Pressed");
} else if ("enableb3".equals(e.getActionCommand())) {
b1.setEnabled(true);
b2.setEnabled(true);
b3.setEnabled(false);
b4.setEnabled(true);
b3.setText("B3 Pressed");
} else if ("enableb4".equals(e.getActionCommand())) {
b1.setEnabled(true);
b2.setEnabled(true);
b3.setEnabled(true);
b4.setEnabled(false);
b4.setText("B4 Pressed");
}
}

/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = ButtonDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {

//Create and set up the window.
JFrame frame = new JFrame("ButtonDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
ButtonDemo newContentPane = new ButtonDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
This post has been viewed 1417 times.

The TextSaver is a simple free tech tool to help save bits of text. You can use it to save notes, text messages, archive text messages from an iPhone or Android, save HTML, avoid PDFs, export messages, lists, phone numbers, addresses, really whatever you want. Please note that saved text is not hidden from the public unless you use the password utility. When using a password, the text will only be viewable to those with a password. Use it for fun, use it for war, use it to control the minds of your enemies.

Legal Disclaimer The website https://textsaver.flap.tv/ (hereinafter referred to as "TextSaver") is a platform designed to allow users to store and share bits of text. TextSaver and its owners do not review, approve, endorse, or make any representations about the legality, accuracy, reliability, completeness, or quality of the content posted by its users. The content reflects the views and responsibility of the person or entity that posts it and does not necessarily represent the views of TextSaver. By using TextSaver, you agree that TextSaver, its owners, affiliates, employees, or agents shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with the use of or reliance on any such content available on or through TextSaver. Users are solely responsible for their content, including compliance with intellectual property laws, confidentiality obligations, and applicable local laws. TextSaver expressly disclaims all liability in relation to the content posted by users. If you believe that any content on TextSaver infringes upon your intellectual property rights or is otherwise unlawful, please contact us with detailed information, and we will take appropriate action in accordance with our policies and applicable laws.