Skip to content

Commit

Permalink
Swing component and demo project example and jdbc pack are added.
Browse files Browse the repository at this point in the history
  • Loading branch information
yrojha4ever committed Nov 19, 2015
1 parent 186a844 commit 07d7bf8
Show file tree
Hide file tree
Showing 16 changed files with 1,380 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<classpathentry kind="src" path="resource"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/ojhay/Documents/GitHub/JavaStud/resource/lib/joda-time-2.8.2.jar"/>
<classpathentry kind="lib" path="C:/Users/ojhay/Documents/GitHub/JavaStud/resource/lib/mysql-connector-java-5.1.6.jar"/>
<classpathentry kind="lib" path="C:/Users/ojhay/Documents/GitHub/JavaStud/forms-1.3.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file added forms-1.3.0.jar
Binary file not shown.
Binary file added miglayout15-swing.jar
Binary file not shown.
Binary file added resource/lib/mysql-connector-java-5.1.6.jar
Binary file not shown.
Binary file added resource/logout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/collection/LinkedHashSetExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

public class LinkedHashSetExample {
public static void main( String[] args ) {

Set< Integer > linkedHashset = new LinkedHashSet< Integer >( );
linkedHashset.addAll( Arrays.asList( 20, 10, 50, 75, 90 ) );
System.out.println( linkedHashset );

Set< String > sHashset = new LinkedHashSet< String >( );
sHashset.addAll( Arrays.asList( "HELLO", "WORLD", "JAVA" ) );
System.out.println( sHashset );

}
}
2 changes: 1 addition & 1 deletion src/collection/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class User implements Serializable {

private static final long serialVersionUID = 6392483654526540237L;
private static final long serialVersionUID = 7031679283226403692L;

private int id;

Expand Down
8 changes: 6 additions & 2 deletions src/collection/UserArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
public class UserArrayList {
public static void main( String[] args ) {

List< User > userList = new ArrayList< User >( );
List< User > userList = new ArrayList< User >( ); // or LinkedList

userList.add( new User( 1, "User1" ) );
userList.add( new User( 2, "User2" ) );
userList.add( new User( 3, "User3" ) );
userList.add( new User( 4, "User4" ) );
userList.add( new User( 5, "User5" ) );

userList.remove( 1 );
System.out.println( "User at index 2: " + userList.get( 2 ) + "\n" );

userList.add( 2, new User( 10, "New USER" ) );

for ( User user: userList ) {
System.out.println( user );
}

}
}
34 changes: 34 additions & 0 deletions src/jdbc/JdbcConnectionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcConnectionTest {
public static void main( String[] args ) {

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

Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/testdb", "root", "" );
// here studentdb is database name, root is username and password

Statement stmt = con.createStatement( );

ResultSet rs = stmt.executeQuery( "select * from student" );

while ( rs.next( ) ) {// Loop Each Row
// Fetch columns
System.out.println( rs.getInt( 1 ) + " " + rs.getString( 2 ) );
}

con.close( );

} catch ( Exception e ) {
System.out.println( e );
}

}

}
15 changes: 15 additions & 0 deletions src/jdbc/MysqlConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlConnection {

public static Connection getConnection( ) throws ClassNotFoundException, SQLException {
Class.forName( "com.mysql.jdbc.Driver" );
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/testdb", "root", "" );
return con;
}

}
244 changes: 244 additions & 0 deletions src/swing/LoginScreenLayout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
package swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
import java.awt.GridLayout;
import javax.swing.JPasswordField;

public class LoginScreenLayout extends JFrame {

private JPanel contentPane;
private JPanel panelTop;
private JPanel panelBottom;
private JPanel panelLeft;
private JPanel panelRight;
private JPanel panelCenter;
private JLabel lblUserName;
private JTextField username;
private JLabel lblPassword;
private JPasswordField password;
private JButton btnSignIn;
private JButton btnCancel;
private JPanel loginPanel;
private JLabel status;

/**
* Launch the application.
*/
public static void main( String[] args ) {
EventQueue.invokeLater( new Runnable( ) {
public void run( ) {
try {
LoginScreenLayout frame = new LoginScreenLayout( );
frame.setVisible( true );
} catch ( Exception e ) {
e.printStackTrace( );
}
}
} );
}

/**
* Create the frame.
*/
public LoginScreenLayout( ) {
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setBounds( 100, 100, 499, 261 );
contentPane = new JPanel( );
contentPane.setBorder( new EmptyBorder( 5, 5, 5, 5 ) );
setContentPane( contentPane );
contentPane.setLayout( new BorderLayout( -2, -2 ) );
contentPane.add( getPanel_1( ), BorderLayout.NORTH );
contentPane.add( getPanel_1_1( ), BorderLayout.SOUTH );
contentPane.add( getPanelLeft( ), BorderLayout.WEST );
contentPane.add( getPanelRight( ), BorderLayout.EAST );
contentPane.add( getPanelCenter( ), BorderLayout.CENTER );
}

private JPanel getPanel_1( ) {
if ( panelTop == null ) {
panelTop = new JPanel( );
FlowLayout flowLayout = ( FlowLayout ) panelTop.getLayout( );
flowLayout.setVgap( 10 );
flowLayout.setHgap( 10 );
panelTop.setBackground( UIManager.getColor( "activeCaption" ) );
panelTop.setForeground( Color.BLACK );
panelTop.setBorder( null );
}
return panelTop;
}

private JPanel getPanel_1_1( ) {
if ( panelBottom == null ) {
panelBottom = new JPanel( );
FlowLayout flowLayout = ( FlowLayout ) panelBottom.getLayout( );
flowLayout.setVgap( 10 );
flowLayout.setHgap( 10 );
panelBottom.setBackground( UIManager.getColor( "activeCaption" ) );
panelBottom.setForeground( Color.BLACK );
}
return panelBottom;
}

private JPanel getPanelLeft( ) {
if ( panelLeft == null ) {
panelLeft = new JPanel( );
FlowLayout flowLayout = ( FlowLayout ) panelLeft.getLayout( );
flowLayout.setVgap( 10 );
flowLayout.setHgap( 10 );
panelLeft.setBackground( UIManager.getColor( "activeCaption" ) );
panelLeft.setForeground( Color.BLACK );
}
return panelLeft;
}

private JPanel getPanelRight( ) {
if ( panelRight == null ) {
panelRight = new JPanel( );
FlowLayout flowLayout = ( FlowLayout ) panelRight.getLayout( );
flowLayout.setVgap( 10 );
flowLayout.setHgap( 10 );
panelRight.setBackground( UIManager.getColor( "activeCaption" ) );
panelRight.setForeground( Color.BLACK );
}
return panelRight;
}

private JPanel getPanelCenter( ) {
if ( panelCenter == null ) {
panelCenter = new JPanel( );
panelCenter.setBackground( new Color( 204, 255, 204 ) );
panelCenter.setBorder( new EtchedBorder( EtchedBorder.LOWERED, null, null ) );
panelCenter.setForeground( Color.BLACK );
panelCenter.setLayout( new FormLayout(new ColumnSpec[] {
FormFactory.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"),
ColumnSpec.decode("6dlu"),
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
ColumnSpec.decode("default:grow"),},
new RowSpec[] {
FormFactory.RELATED_GAP_ROWSPEC,
RowSpec.decode("default:grow"),
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,}) );
panelCenter.add( getLoginPanel( ), "2, 2, 9, 8, fill, fill" );
panelCenter.add(getStatus(), "8, 10, 3, 1");
panelCenter.add( getBtnSignIn( ), "4, 14" );
panelCenter.add( getBtnCancel( ), "10, 14" );
}
return panelCenter;
}

private JLabel getLblUserName( ) {
if ( lblUserName == null ) {
lblUserName = new JLabel( "User Name:" );
lblUserName.setFont( new Font( "Tahoma", Font.BOLD, 13 ) );
}
return lblUserName;
}

private JTextField getUsername( ) {
if ( username == null ) {
username = new JTextField( );
username.setSize( 250, 30 );
username.setColumns( 10 );
}
return username;
}

private JLabel getLblPassword( ) {
if ( lblPassword == null ) {
lblPassword = new JLabel( "Password:" );
lblPassword.setFont( new Font( "Tahoma", Font.BOLD, 13 ) );
}
return lblPassword;
}

private JPasswordField getPassword( ) {
if ( password == null ) {
password = new JPasswordField( );
password.setColumns( 10 );
}
return password;
}

private JButton getBtnSignIn( ) {
if ( btnSignIn == null ) {
btnSignIn = new JButton( "Sign In" );
btnSignIn.setFont( new Font( "Tahoma", Font.BOLD, 11 ) );
}
return btnSignIn;
}

private JButton getBtnCancel( ) {
if ( btnCancel == null ) {
btnCancel = new JButton( "Cancel" );
btnCancel.addActionListener( new ActionListener( ) {
@Override
public void actionPerformed( ActionEvent e ) {
System.exit( 0 );
}
} );
}
return btnCancel;
}

private JPanel getLoginPanel( ) {
if ( loginPanel == null ) {
loginPanel = new JPanel( );
loginPanel.setBorder( new TitledBorder( UIManager.getBorder( "TitledBorder.border" ), "Login", TitledBorder.LEADING, TitledBorder.TOP, null, new Color( 0, 0, 0 ) ) );
loginPanel.setLayout(new GridLayout(2, 3, 2, 2));
loginPanel.add( getLblUserName( ) );
loginPanel.add( getUsername( ) );
loginPanel.add( getLblPassword( ) );
loginPanel.add( getPassword( ) );
}
return loginPanel;
}

private JLabel getStatus() {
if (status == null) {
status = new JLabel("Status:");
status.setForeground(new Color(204, 0, 102));
status.setFont(new Font("Tahoma", Font.BOLD, 11));
}
return status;
}
}
Loading

0 comments on commit 07d7bf8

Please sign in to comment.