Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button login and cancel such that clicking in login checks for matching user id and password in the database and opens another window if login is successful and displays appropriate message if login is not successful. Clicking in cancel terminates our program.

 Let us suppose we have a database named user and a table named user_table with fields user_id and password. Now the complete code for the above task is given below:


//UserInterfaceDesign.java

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

import javax.swing.*;

public class UserInterfaceDesign extends JFrame {

JLabel user_id_label = new JLabel("User ID:");

JTextField user_id_field = new JTextField(10);

JLabel password_label = new JLabel("Password:");

JPasswordField password_field = new JPasswordField(10);

JLabel account_type_label = new JLabel("Account Type:");

JRadioButton account_type_radio_button1 = new JRadioButton("Savings");

JRadioButton account_type_radio_button2 = new JRadioButton("Current");

ButtonGroup account_type_button_group = new ButtonGroup();

JButton login_button = new JButton("LogIn");

JButton cancel_button = new JButton("Cancel");

JButton edit_button = new JButton("Edit");

public UserInterfaceDesign() {

account_type_button_group.add(account_type_radio_button1);

account_type_button_group.add(account_type_radio_button2);

JPanel p1 = new JPanel(new FlowLayout(10));

p1.add(user_id_label);

p1.add(user_id_field);

p1.add(password_label);

p1.add(password_field);

p1.add(account_type_label);

p1.add(account_type_radio_button1);

p1.add(account_type_radio_button2);

add(p1,BorderLayout.NORTH);

JPanel p2 = new JPanel(new FlowLayout(50));

p2.add(login_button);

p2.add(cancel_button);

p2.add(edit_button);

add(p2,BorderLayout.SOUTH);

login_button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

try{

Class.forName("com.mysql.jdbc.Driver");

Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root",null);

Statement s = c.createStatement();

int id = Integer.parseInt(user_id_field.getText());

char [] pass = password_field.getPassword();

String passwd = String.valueOf(pass);

System.out.println("ID:"+id+"\tPassword:"+passwd);

String sql = "SELECT * FROM user_table WHERE user_id = "+id+" AND password='"+passwd+"'";

ResultSet r = s.executeQuery(sql);

if(r.first()) {

JOptionPane.showMessageDialog(new JFrame(), "Log In Successful!!!");

}

else {

JOptionPane.showMessageDialog(null, "Incorrect UserID/Password");

}

}

catch (Exception ex){

System.out.println("Exception occurred");

}

}

});

cancel_button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

setSize(700,300);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String []args) {

new UserInterfaceDesign();

}

}

Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?

Explain network topology .Explain tis types with its advantages and disadvantges.