import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Font;
public class Lab3 extends JFrame {
/**
* Creates new form Lab3
*/
public Lab3() {
initComponents();
txtAreaActions txtAreaAct = new txtAreaActions();
txtArea.addActionListener(txtAreaAct);
clearAll clear = new clearAll();
cmdReset.addActionListener(clear);
exit exitWindow = new exit();
cmdExit.addActionListener(exitWindow);
ButtonActions btnAct = new ButtonActions();
btnSmall.addMouseListener(btnAct);
}
public class txtAreaActions implements ActionListener {
public void actionPerformed(ActionEvent event) {
String usrInput = txtArea.getText();
usrInput = usrInput.trim();
txtAreaChange.setText(usrInput);
}
}
public class clearAll implements ActionListener{
public void actionPerformed(ActionEvent event)
{
String usrResult = txtAreaChange.getText();
txtAreaChange.setText("");
txtArea.setText("");
}
}
public class exit extends JOptionPane implements ActionListener{
public void actionPerformed(ActionEvent event)
{
int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to Exit?", "Exit", JOptionPane.YES_NO_OPTION);
if(answer==0)
{
System.exit(answer);
}
}
}
public class ButtonActions implements MouseListener, ActionListener{
public void mouseClicked(MouseEvent event) {
public void actionPerformed(ActionEvent event)
{
String usrInput = txtArea.getText();
usrInput = usrInput.trim();
txtAreaChange.setText(usrInput);
Font oldFont = txtAreaChange.getFont();
if(event.getSource()==btnSmall)
{
Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), 12);
txtAreaChange.setFont(newFont);
}
}
public void mousePressed(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
grpTxtSize = new javax.swing.ButtonGroup();
grpAlign = new javax.swing.ButtonGroup();
pnlTopLeft = new javax.swing.JPanel();
lblTextSize = new javax.swing.JLabel();
lblAign = new javax.swing.JLabel();
lblChangeTxt = new javax.swing.JLabel();
btnSmall = new javax.swing.JRadioButton();
btnMedium = new javax.swing.JRadioButton();
btnLarge = new javax.swing.JRadioButton();
btnLeft = new javax.swing.JRadioButton();
btnCentre = new javax.swing.JRadioButton();
btnRight = new javax.swing.JRadioButton();
txtArea = new javax.swing.JTextField();
pnlMid = new javax.swing.JPanel();
txtAreaChange = new javax.swing.JTextField();
pnlBot = new javax.swing.JPanel();
cmdReset = new javax.swing.JButton();
cmdExit = new javax.swing.JButton();
pnlRight = new javax.swing.JPanel();
lblFont = new javax.swing.JLabel();
btnBold = new javax.swing.JCheckBox();
btnItalic = new javax.swing.JCheckBox();
lblForeground = new javax.swing.JLabel();
cmbFore = new javax.swing.JComboBox();
lblBackground = new javax.swing.JLabel();
cmbBack = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Lab 3 - Jonathan Tesoro");
lblTextSize.setText("Text Size:");
lblAign.setText("Alignment:");
lblChangeTxt.setText("Change Text:");
grpTxtSize.add(btnSmall);
btnSmall.setText("Small");
grpTxtSize.add(btnMedium);
btnMedium.setText("Medium");
grpTxtSize.add(btnLarge);
btnLarge.setText("Large");
grpAlign.add(btnLeft);
btnLeft.setText("Left");
grpAlign.add(btnCentre);
btnCentre.setText("Centre");
grpAlign.add(btnRight);
btnRight.setText("Right");
javax.swing.GroupLayout pnlTopLeftLayout = new javax.swing.GroupLayout(pnlTopLeft);
pnlTopLeft.setLayout(pnlTopLeftLayout);
pnlTopLeftLayout.setHorizontalGroup(
pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlTopLeftLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblTextSize)
.addComponent(lblAign)
.addComponent(lblChangeTxt))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlTopLeftLayout.createSequentialGroup()
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnSmall)
.addComponent(btnLeft))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnMedium)
.addComponent(btnCentre))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnRight)
.addComponent(btnLarge)))
.addComponent(txtArea, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlTopLeftLayout.setVerticalGroup(
pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlTopLeftLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblTextSize)
.addComponent(btnSmall)
.addComponent(btnMedium)
.addComponent(btnLarge))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblAign)
.addComponent(btnLeft)
.addComponent(btnCentre)
.addComponent(btnRight))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlTopLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblChangeTxt)
.addComponent(txtArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
txtAreaChange.setEditable(false);
txtAreaChange.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout pnlMidLayout = new javax.swing.GroupLayout(pnlMid);
pnlMid.setLayout(pnlMidLayout);
pnlMidLayout.setHorizontalGroup(
pnlMidLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMidLayout.createSequentialGroup()
.addContainerGap()
.addComponent(txtAreaChange)
.addContainerGap())
);
pnlMidLayout.setVerticalGroup(
pnlMidLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMidLayout.createSequentialGroup()
.addContainerGap()
.addComponent(txtAreaChange)
.addContainerGap())
);
cmdReset.setMnemonic('R');
cmdReset.setText("Reset");
cmdExit.setMnemonic('x');
cmdExit.setText("Exit");
javax.swing.GroupLayout pnlBotLayout = new javax.swing.GroupLayout(pnlBot);
pnlBot.setLayout(pnlBotLayout);
pnlBotLayout.setHorizontalGroup(
pnlBotLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlBotLayout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(cmdReset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(cmdExit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(74, 74, 74))
);
pnlBotLayout.setVerticalGroup(
pnlBotLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBotLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pnlBotLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdReset)
.addComponent(cmdExit))
.addContainerGap())
);
lblFont.setText("Font Options:");
btnBold.setText("Bold");
btnItalic.setText("Italic");
lblForeground.setText("Foreground:");
cmbFore.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Red", "Blue", "Green", "Black" }));
lblBackground.setText("Background:");
cmbBack.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Grey", "Yellow", "Pink", "Magenta" }));
javax.swing.GroupLayout pnlRightLayout = new javax.swing.GroupLayout(pnlRight);
pnlRight.setLayout(pnlRightLayout);
pnlRightLayout.setHorizontalGroup(
pnlRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlRightLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmbFore, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblForeground)
.addComponent(btnItalic)
.addComponent(btnBold)
.addComponent(lblFont)
.addComponent(lblBackground)
.addComponent(cmbBack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(24, Short.MAX_VALUE))
);
pnlRightLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cmbBack, cmbFore});
pnlRightLayout.setVerticalGroup(
pnlRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlRightLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblFont)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnBold)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnItalic)
.addGap(18, 18, 18)
.addComponent(lblForeground)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbFore, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblBackground)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbBack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(80, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlTopLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlBot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlMid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(38, 38, 38))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pnlTopLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlMid, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(pnlBot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(82, 82, 82))
.addGroup(layout.createSequentialGroup()
.addComponent(pnlRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(88, 88, 88))))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Lab3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Lab3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Lab3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Lab3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Lab3().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JCheckBox btnBold;
private javax.swing.JRadioButton btnCentre;
private javax.swing.JCheckBox btnItalic;
private javax.swing.JRadioButton btnLarge;
private javax.swing.JRadioButton btnLeft;
private javax.swing.JRadioButton btnMedium;
private javax.swing.JRadioButton btnRight;
private javax.swing.JRadioButton btnSmall;
private javax.swing.JComboBox cmbBack;
private javax.swing.JComboBox cmbFore;
private javax.swing.JButton cmdExit;
private javax.swing.JButton cmdReset;
private javax.swing.ButtonGroup grpAlign;
private javax.swing.ButtonGroup grpTxtSize;
private javax.swing.JLabel lblAign;
private javax.swing.JLabel lblBackground;
private javax.swing.JLabel lblChangeTxt;
private javax.swing.JLabel lblFont;
private javax.swing.JLabel lblForeground;
private javax.swing.JLabel lblTextSize;
private javax.swing.JPanel pnlBot;
private javax.swing.JPanel pnlMid;
private javax.swing.JPanel pnlRight;
private javax.swing.JPanel pnlTopLeft;
private javax.swing.JTextField txtArea;
private javax.swing.JTextField txtAreaChange;
// End of variables declaration
}