Java FX Change this code to another one that does the same but do not looks the
ID: 3601037 • Letter: J
Question
Java FX
Change this code to another one that does the same but do not looks the same
Code:
package Project-03 Application Viewer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Project-03 Application Viewer extends JFrame implements ActionListener
{
JLabel l1, l2, l3, l4, l5, l6, l7, l8;
JTextField tf1, tf2, tf5, tf6, tf7;
JButton btn1, btn2;
JPasswordField p1, p2;
JavaFXApplication1()
{
setVisible(true);
setSize(900, 900);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Registration Form in Java");
l1 = new JLabel("Registration Form in Windows Form:");
l1.setForeground(Color.blue);
l1.setFont(new Font("Serif", Font.BOLD, 18));
l2 = new JLabel("Name:");
l3 = new JLabel("Email-ID:");
l4 = new JLabel("Create Passowrd:");
l5 = new JLabel("Confirm Password:");
l6 = new JLabel("Country:");
l7 = new JLabel("State:");
l8 = new JLabel("Phone No:");
tf1 = new JTextField();
tf2 = new JTextField();
p1 = new JPasswordField();
p2 = new JPasswordField();
tf5 = new JTextField();
tf6 = new JTextField();
tf7 = new JTextField();
btn1 = new JButton("Submit");
btn2 = new JButton("Clear");
btn1.addActionListener(this);
btn2.addActionListener(this);
l1.setBounds(100, 30, 400, 30);
l2.setBounds(80, 70, 200, 30);
l3.setBounds(80, 110, 200, 30);
l4.setBounds(80, 150, 200, 30);
l5.setBounds(80, 190, 200, 30);
l6.setBounds(80, 230, 200, 30);
l7.setBounds(80, 270, 200, 30);
l8.setBounds(80, 310, 200, 30);
tf1.setBounds(300, 70, 200, 30);
tf2.setBounds(300, 110, 200, 30);
p1.setBounds(300, 150, 200, 30);
p2.setBounds(300, 190, 200, 30);
tf5.setBounds(300, 230, 200, 30);
tf6.setBounds(300, 270, 200, 30);
tf7.setBounds(300, 310, 200, 30);
btn1.setBounds(50, 350, 100, 30);
btn2.setBounds(170, 350, 100, 30);
add(l1);
add(l2);
add(tf1);
add(l3);
add(tf2);
add(l4);
add(p1);
add(l5);
add(p2);
add(l6);
add(tf5);
add(l7);
add(tf6);
add(l8);
add(tf7);
add(btn1);
add(btn2);
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btn1)
{
int x = 0;
String s1 = tf1.getText();
String s2 = tf2.getText();
char[] s3 = p1.getPassword();
char[] s4 = p2.getPassword();
String s8 = new String(s3);
String s9 = new String(s4);
String s5 = tf5.getText();
String s6 = tf6.getText();
String s7 = tf7.getText();
if (s8.equals(s9))
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "Hello", "welcome");
PreparedStatement ps = con.prepareStatement("insert into reg values(?,?,?,?,?,?)");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s8);
ps.setString(4, s5);
ps.setString(5, s6);
ps.setString(6, s7);
ResultSet rs = ps.executeQuery();
x++;
if (x > 0)
{
JOptionPane.showMessageDialog(btn1, "Data Saved");
}
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else
{
JOptionPane.showMessageDialog(btn1, "Password Does Not Match");
}
}
else
{
tf1.setText("");
tf2.setText("");
p1.setText("");
p2.setText("");
tf5.setText("");
tf6.setText("");
tf7.setText("");
}
}
public static void main(String args[])
{
new Project-03 Application Viewer();
}
}
Explanation / Answer
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class ApplicationViewer extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, jLabel7, jLabel8;
JTextField jTextField1, jTextField2, jTextField5, jTextField6, jTextField7;
JButton jButton1, jButton2;
JPasswordField jPasswordField1, jPasswordField2;
ApplicationViewer() {
setVisible(true);
setSize(900, 900);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Registration Form in Java");
jLabel1 = new JLabel("Registration Form in Windows Form:");
jLabel1.setForeground(Color.blue);
jLabel1.setFont(new Font("Serif", Font.BOLD, 18));
jLabel2 = new JLabel("Name:");
jLabel3 = new JLabel("Email-ID:");
jLabel4 = new JLabel("Create Passowrd:");
jLabel5 = new JLabel("Confirm Password:");
jLabel6 = new JLabel("Country:");
jLabel7 = new JLabel("State:");
jLabel8 = new JLabel("Phone No:");
jTextField1 = new JTextField();
jTextField2 = new JTextField();
jPasswordField1 = new JPasswordField();
jPasswordField2 = new JPasswordField();
jTextField5 = new JTextField();
jTextField6 = new JTextField();
jTextField7 = new JTextField();
jButton1 = new JButton("Submit");
jButton2 = new JButton("Clear");
jButton1.addActionListener(this);
jButton2.addActionListener(this);
jLabel1.setBounds(100, 30, 400, 30);
jLabel2.setBounds(80, 70, 200, 30);
jLabel3.setBounds(80, 110, 200, 30);
jLabel4.setBounds(80, 150, 200, 30);
jLabel5.setBounds(80, 190, 200, 30);
jLabel6.setBounds(80, 230, 200, 30);
jLabel7.setBounds(80, 270, 200, 30);
jLabel8.setBounds(80, 310, 200, 30);
jTextField1.setBounds(300, 70, 200, 30);
jTextField2.setBounds(300, 110, 200, 30);
jPasswordField1.setBounds(300, 150, 200, 30);
jPasswordField2.setBounds(300, 190, 200, 30);
jTextField5.setBounds(300, 230, 200, 30);
jTextField6.setBounds(300, 270, 200, 30);
jTextField7.setBounds(300, 310, 200, 30);
jButton1.setBounds(50, 350, 100, 30);
jButton2.setBounds(170, 350, 100, 30);
add(jLabel1);
add(jLabel2);
add(jTextField1);
add(jLabel3);
add(jTextField2);
add(jLabel4);
add(jPasswordField1);
add(jLabel5);
add(jPasswordField2);
add(jLabel6);
add(jTextField5);
add(jLabel7);
add(jTextField6);
add(jLabel8);
add(jTextField7);
add(jButton1);
add(jButton2);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jButton1) {
int x = 0;
String s1 = jTextField1.getText();
String s2 = jTextField2.getText();
char[] s3 = jPasswordField1.getPassword();
char[] s4 = jPasswordField2.getPassword();
String s8 = new String(s3);
String s9 = new String(s4);
String s5 = jTextField5.getText();
String s6 = jTextField6.getText();
String s7 = jTextField7.getText();
if (s8.equals(s9)) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "Hello",
"welcome");
PreparedStatement ps = con.prepareStatement("insert into reg values(?,?,?,?,?,?)");
ps.setString(1, s1);
ps.setString(2, s2);
ps.setString(3, s8);
ps.setString(4, s5);
ps.setString(5, s6);
ps.setString(6, s7);
ResultSet rs = ps.executeQuery();
x++;
if (x > 0) {
JOptionPane.showMessageDialog(jButton1, "Data Saved");
}
} catch (Exception ex) {
System.out.println(ex);
}
} else {
JOptionPane.showMessageDialog(jButton1, "Password do not Match");
}
} else {
jTextField1.setText("");
jTextField2.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
}
}
public static void main(String args[]) {
new ApplicationViewer();
}
}
=================
Things changed:
1. I have changed the variable naming
2. I have changed the convention
All other things are same, the functionality is same
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.