exampleframe.java
import java.awt.Color;
import static java.lang.System.exit;
import java.text.DateFormat;
import java.util.Date;
import javafx.scene.layout.Border;
import javax.swing.BorderFactory;
public class exampleframe extends javax.swing.JFrame {
public exampleframe() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField1.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jTextField1.setForeground(new java.awt.Color(51, 51, 255));
jTextField1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(102, 255, 204)));
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jLabel1.setText("Enter your Name:");
jLabel2.setBackground(new java.awt.Color(102, 255, 0));
jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jLabel2.setForeground(new java.awt.Color(0, 51, 255));
jButton1.setBackground(new java.awt.Color(102, 255, 102));
jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jButton1.setForeground(new java.awt.Color(255, 0, 255));
jButton1.setText("CLICK ME");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(102, 255, 102));
jButton2.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jButton2.setForeground(new java.awt.Color(255, 0, 255));
jButton2.setText("CLEAR");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setBackground(new java.awt.Color(102, 255, 102));
jButton3.setFont(new java.awt.Font("Comic Sans MS", 1, 14));
jButton3.setForeground(new java.awt.Color(255, 51, 255));
jButton3.setText("EXIT");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel3.setBackground(new java.awt.Color(255, 255, 102));
jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 24));
jLabel3.setForeground(new java.awt.Color(255, 51, 51));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(49, 49, 49))
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(32, 32, 32)
.addComponent(jButton3))
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(41, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19))
);
pack();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
exit(0) ;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jLabel2.setText("");
jTextField1.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
javax.swing.border.Border blackline = BorderFactory.createLineBorder(Color.red);
jLabel2.setBorder(blackline);
String s = "";
jLabel3.setText(DateFormat.getDateTimeInstance().format(new Date()));
jLabel2.setEnabled(true);
if (DateFormat.getDateTimeInstance().format(new Date()).contains("PM")) {
s = "GOOD EVENING ";
} else {
s = "GOOD MORNING ";
}
jLabel2.setText(s+jTextField1.getText());
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new exampleframe().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField jTextField1;
}
OUTPUT:
No comments:
Post a Comment