Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.ImageIcon;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author darya
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- initComponents();
- buttonGroup1.add(jRadioButton1);
- buttonGroup1.add(jRadioButton2);
- buttonGroup1.add(jRadioButton3);
- }
- /**
- * 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() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- jPanel2 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jToggleButton1 = new javax.swing.JToggleButton();
- jPanel1 = new javax.swing.JPanel();
- jLabel4 = new javax.swing.JLabel();
- jComboBox1 = new javax.swing.JComboBox<>();
- jTextField1 = new javax.swing.JTextField();
- jLabel5 = new javax.swing.JLabel();
- jCheckBox1 = new javax.swing.JCheckBox();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- getContentPane().setLayout(new java.awt.GridLayout(1, 2));
- jPanel2.setBackground(new java.awt.Color(204, 204, 204));
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
- jLabel1.setText("homework 1");
- jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/content-icon.png"))); // NOI18N
- jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
- jLabel3.setText("screen mode");
- jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/off.png"))); // NOI18N
- jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jToggleButton1ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(66, 66, 66)
- .addComponent(jLabel2))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(124, 124, 124)
- .addComponent(jLabel1))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(56, 56, 56)
- .addComponent(jToggleButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jLabel3)))
- .addContainerGap(116, Short.MAX_VALUE))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(60, 60, 60)
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
- .addGap(36, 36, 36))
- );
- getContentPane().add(jPanel2);
- jPanel1.setBackground(java.awt.Color.white);
- jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jLabel4.setText("enter a sentence");
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "select font", "bold", "italic", "bold-italic", "plain" }));
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jLabel5.setText("select your subject");
- jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jCheckBox1.setText("agree to conditions and terms");
- jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jCheckBox1ActionPerformed(evt);
- }
- });
- jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jRadioButton1.setText("programming");
- jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton1ActionPerformed(evt);
- }
- });
- jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jRadioButton2.setText("database");
- jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton2ActionPerformed(evt);
- }
- });
- jRadioButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jRadioButton3.setText("network");
- jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton3ActionPerformed(evt);
- }
- });
- jButton1.setText("finish");
- jButton1.setEnabled(false);
- jButton2.setText("reset");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(59, 59, 59)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jTextField1)
- .addGap(18, 18, 18)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(42, 42, 42))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton1))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jRadioButton1)
- .addGap(18, 18, 18)
- .addComponent(jRadioButton2)
- .addGap(18, 18, 18)
- .addComponent(jRadioButton3))
- .addComponent(jCheckBox1)
- .addComponent(jLabel5)))
- .addGap(0, 42, Short.MAX_VALUE))))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(49, 49, 49)
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(68, 68, 68)
- .addComponent(jLabel5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton1)
- .addComponent(jRadioButton2)
- .addComponent(jRadioButton3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
- .addComponent(jCheckBox1)
- .addGap(83, 83, 83)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap())
- );
- getContentPane().add(jPanel1);
- pack();
- }// </editor-fold>
- private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jCheckBox1.isSelected()) {
- jButton1.setEnabled(true);
- } else {
- jButton1.setEnabled(false);
- }
- }
- private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jToggleButton1.isSelected()) {
- ImageIcon ic = new ImageIcon("src\\on.png");
- jToggleButton1.setIcon(ic);
- jPanel1.setBackground(Color.black);
- jPanel2.setBackground(Color.white);
- jLabel4.setForeground(Color.white);
- jLabel5.setForeground(Color.white);
- jRadioButton1.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- jRadioButton3.setForeground(Color.white);
- jCheckBox1.setForeground(Color.white);
- } else {
- ImageIcon ic = new ImageIcon("src\\off.png");
- jToggleButton1.setIcon(ic);
- jPanel1.setBackground(Color.white);
- jPanel2.setBackground(Color.lightGray);
- jLabel4.setForeground(Color.black);
- jLabel5.setForeground(Color.black);
- jRadioButton1.setForeground(Color.black);
- jRadioButton2.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- jCheckBox1.setForeground(Color.black);
- }
- }
- private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jRadioButton1.isSelected()) {
- jRadioButton1.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton2.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton2.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton2.isSelected()) {
- jRadioButton2.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton3.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton3.isSelected()) {
- jRadioButton3.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton2.setForeground(Color.black);
- }
- }
- }
- private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jRadioButton1.isSelected()) {
- jRadioButton1.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton2.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton2.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton2.isSelected()) {
- jRadioButton2.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton3.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton3.isSelected()) {
- jRadioButton3.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton2.setForeground(Color.black);
- }
- }
- // TODO add your handling code here:
- }
- private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jRadioButton1.isSelected()) {
- jRadioButton1.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton2.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton2.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton2.isSelected()) {
- jRadioButton2.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton3.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- } else if (jRadioButton3.isSelected()) {
- jRadioButton3.setForeground(Color.pink);
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton2.setForeground(Color.black);
- }
- }
- }
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- if (jComboBox1.getSelectedIndex() == 1) {
- Font font = new Font("Arial", Font.BOLD, 13);
- jTextField1.setFont(font);
- } else if (jComboBox1.getSelectedIndex() == 2) {
- Font font = new Font("Arial", Font.ITALIC, 13);
- jTextField1.setFont(font);
- } else if (jComboBox1.getSelectedIndex() == 3) {
- Font font = new Font("Arial", Font.BOLD + Font.ITALIC, 13);
- jTextField1.setFont(font);
- } else if (jComboBox1.getSelectedIndex() == 4) {
- Font font = new Font("Arial", Font.PLAIN, 13);
- jTextField1.setFont(font);
- }
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- jTextField1.setText("");
- jComboBox1.setSelectedIndex(0);
- buttonGroup1.clearSelection();
- if (jToggleButton1.isSelected()) {
- jRadioButton1.setForeground(Color.white);
- jRadioButton2.setForeground(Color.white);
- jRadioButton3.setForeground(Color.white);
- } else {
- jRadioButton1.setForeground(Color.black);
- jRadioButton2.setForeground(Color.black);
- jRadioButton3.setForeground(Color.black);
- }
- jCheckBox1.setSelected(false);
- jButton1.setEnabled(false);
- }
- /**
- * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JComboBox<String> jComboBox1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JToggleButton jToggleButton1;
- // End of variables declaration
- }
Add Comment
Please, Sign In to add comment