Tuesday, November 24, 2015

JavaFx Sqlite Database Tutorial 5 - How to show and hide a window in Jav...







package application;

import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class LoginController implements Initializable {
 public LoginModel loginModel = new LoginModel();
 
 
   @FXML
   private Label isConnected;
   
   @FXML
   private TextField txtUsername;
   
   @FXML
   private TextField txtPassword;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  // TODO Auto-generated method stub
  if (loginModel.isDbConnected()) {
   isConnected.setText("Connected");
  } else {

   isConnected.setText("Not Connected");
  }
 }
 
 public void Login (ActionEvent event) {
  try {
   if (loginModel.isLogin(txtUsername.getText(), txtPassword.getText())) {
    isConnected.setText("username and password is correct");
    ((Node)event.getSource()).getScene().getWindow().hide();
    Stage primaryStage = new Stage();
    FXMLLoader loader = new FXMLLoader();
    Pane root = loader.load(getClass().getResource("/application/User.fxml").openStream());
    UserController userController = (UserController)loader.getController();
    userController.GetUser(txtUsername.getText());
    Scene scene = new Scene(root);
    scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.show();
    
    
   } else {
    isConnected.setText("username and password is not correct");
   }
  } catch (SQLException e) {
   isConnected.setText("username and password is not correct");
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
  
}




package application;
import java.sql.*;
public class LoginModel {
  Connection conection;
  public LoginModel () {
   conection = SqliteConnection.Connector();
   if (conection == null) {

   System.out.println("connection not successful");
    System.exit(1);}
  }
  
  public boolean isDbConnected() {
   try {
  return !conection.isClosed();
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return false;
 }
}
  public boolean isLogin(String user, String pass) throws SQLException {
   PreparedStatement preparedStatement = null;
   ResultSet resultSet = null;
   String query = "select * from employee where username = ? and password = ?";
   try {    
    preparedStatement = conection.prepareStatement(query);
    preparedStatement.setString(1, user);
    preparedStatement.setString(2, pass);
    
    resultSet = preparedStatement.executeQuery();
    if (resultSet.next()) {
     return true;
    } 
    else {
     return false;
    }
  
 } catch (Exception e) {
    return false;
  // TODO: handle exception
 } finally {
  preparedStatement.close();
  resultSet.close();
 }
  }
}




package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
 

public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Login.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}




package application;
import java.sql.*;
public class SqliteConnection {
  public static Connection Connector() {
 try {
  Class.forName("org.sqlite.JDBC");
  Connection conn =DriverManager.getConnection("jdbc:sqlite:EmployeeDb.sqlite");
  return conn;
 } catch (Exception e) {
  System.out.println(e);
  return null;
  // TODO: handle exception
 }
}
}




package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class UserController implements Initializable {
    @FXML
    private Label userLbl;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  // TODO Auto-generated method stub
  
 }
 
 public void GetUser(String user) {
  // TODO Auto-generated method stub
  userLbl.setText(user);
 }
 
 public void SignOut(ActionEvent event) {
  try {
   ((Node)event.getSource()).getScene().getWindow().hide();
   Stage primaryStage = new Stage();
   FXMLLoader loader = new FXMLLoader();
   Pane root = loader.load(getClass().getResource("/application/Login.fxml").openStream());
   
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch (Exception e) {
   // TODO: handle exception
  }
 }

}




<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="302.0" prefWidth="367.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.LoginController">
   <children>
      <Label fx:id="isConnected" layoutY="35.0" prefHeight="46.0" prefWidth="367.0" text="Status" textFill="#cd1313">
         <font>
            <Font size="18.0" />
         </font>
      </Label>
      <TextField fx:id="txtUsername" layoutX="54.0" layoutY="108.0" promptText="User Name">
         <font>
            <Font size="18.0" />
         </font>
      </TextField>
      <PasswordField fx:id="txtPassword" layoutX="54.0" layoutY="157.0" promptText="Password">
         <font>
            <Font size="18.0" />
         </font>
      </PasswordField>
      <Button layoutX="103.0" layoutY="216.0" mnemonicParsing="false" onAction="#Login" text="Login">
         <font>
            <Font size="18.0" />
         </font>
      </Button>
   </children>
</AnchorPane>




<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.UserController">
   <top>
      <HBox BorderPane.alignment="CENTER">
         <children>
            <Label fx:id="userLbl" prefHeight="34.0" prefWidth="106.0" text="User Welcome" />
            <Button mnemonicParsing="false" onAction="#SignOut" prefHeight="28.0" prefWidth="103.0" text="Sign Out" />
         </children>
      </HBox>
   </top>
</BorderPane>















Thursday, November 19, 2015

JavaFx Tutorial For Beginners 17 - JavaFX Properties

JavaFX Properties









package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}




package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class MainController implements Initializable {
 final MyNumber myNum = new MyNumber();
    
    @FXML
    private Label lblStatus;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  myNum.setNumber(0);
  myNum.numberProperty().addListener(new ChangeListener<Object>() {

   @Override
   public void changed(ObservableValue<? extends Object> observable,
     Object oldValue, Object newValue) {
    lblStatus.setText(new Double(myNum.getNumber()).toString());
    
   }
  });
  
 }
 
 public void BtnClick(ActionEvent event) {
  myNum.setNumber(myNum.getNumber() + 1);
 }

}




package application;
import javafx.beans.property.*;
public class MyNumber {
 private DoubleProperty number;

 public final double getNumber() {
  if (number != null)
  return number.get();
  return 0;
 }

 public final void setNumber(double number) {
  this.numberProperty().set(number); 
 }
 

 public final DoubleProperty numberProperty() { 
        if (number == null) { 
            number = new SimpleDoubleProperty(0); 
        } 
        return number; 
    } 
}






<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane maxWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40" fx:controller="application.MainController">
   <children>
      <Button layoutX="117.0" layoutY="171.0" mnemonicParsing="false" onAction="#BtnClick" prefHeight="63.0" prefWidth="104.0" text="Button" />
      <Label fx:id="lblStatus" layoutX="117.0" layoutY="72.0" prefHeight="52.0" prefWidth="104.0" text="Label" />
   </children>
</AnchorPane>







Saturday, November 14, 2015

JavaFx Sqlite Database Tutorial 2 - How Connect Sqlite to JavaFx







package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class LoginController implements Initializable {
 public LoginModel loginModel = new LoginModel();
 
 
   @FXML
   private Label isConnected;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  // TODO Auto-generated method stub
  if (loginModel.isDbConnected()) {
   isConnected.setText("Connected");
  } else {

   isConnected.setText("Not Connected");
  }
 }
  
}




package application;
import java.sql.*;
public class LoginModel {
  Connection conection;
  public LoginModel () {
   conection = SqliteConnection.Connector();
   if (conection == null) {

   System.out.println("connection not successful");
    System.exit(1);}
  }
  
  public boolean isDbConnected() {
   try {
  return !conection.isClosed();
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return false;
 }
}
}



package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
 

public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Login.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}



package application;
import java.sql.*;
public class SqliteConnection {
  public static Connection Connector() {
 try {
  Class.forName("org.sqlite.JDBC");
  Connection conn =DriverManager.getConnection("jdbc:sqlite:EmployeeDb.sqlite");
  return conn;
 } catch (Exception e) {
  System.out.println(e);
  return null;
  // TODO: handle exception
 }
}
}



<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.LoginController">
   <children>
      <Label fx:id="isConnected" layoutX="54.0" layoutY="35.0" prefHeight="46.0" prefWidth="192.0" text="Status" textFill="#cd1313">
         <font>
            <Font size="18.0" />
         </font>
      </Label>
   </children>
</AnchorPane>



Javascript Tutorial For Beginners 11 # JavaScript for Loop







<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>javascript</title>
</head>
<body >
<p id="demo"></p>
<p id="demo1"></p>

<script type="text/javascript">
var a;
var result="";
/* while (a <= 10) {
  result += "<br>" + a;
  a++;
 }*/

var names = ["tom", "mark","Ben","jack","john"];
for (a=0,result=""; a < names.length ; a++) {
 result += "<br>" + names[a];
}
document.getElementById("demo").innerHTML= result ;

var student = {name:"Mark", surname:"tesar", age:22};
var x;
var result1="";
for (x in student)
 result1 += "<br>" + student[x];
document.getElementById("demo1").innerHTML= result1 ;

</script>
</body>
</html>







JavaFx Tutorial For Beginners 14 - JavaFX TreeView




package application;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;


public class Main extends Application {
 @Override
 public void start(Stage primaryStage) {
  try {
   Parent root = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
   Scene scene = new Scene(root);
   scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
   primaryStage.setScene(scene);
   primaryStage.show();
  } catch(Exception e) {
   e.printStackTrace();
  }
 }
 
 public static void main(String[] args) {
  launch(args);
 }
}




package application;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;

public class MainController implements Initializable {
    
 @FXML
 TreeView <String> treeView;
 
 Image icon = new Image (
   getClass().getResourceAsStream("/img/icon.png"));
 
 @Override
 public void initialize(URL location, ResourceBundle resources) {
  TreeItem<String> root = new TreeItem<>("Root", new ImageView(icon));
  root.setExpanded(true);

  TreeItem<String> nodeA = new TreeItem<>("node A", new ImageView(icon));
  TreeItem<String> nodeB = new TreeItem<>("node B", new ImageView(icon));
  TreeItem<String> nodeC = new TreeItem<>("node C", new ImageView(icon));
  root.getChildren().addAll(nodeA,nodeB,nodeC);
  nodeA.setExpanded(true);
  
  TreeItem<String> nodeA1 = new TreeItem<>("node A 1", new ImageView(icon));
  TreeItem<String> nodeB1 = new TreeItem<>("node B 1", new ImageView(icon));
  TreeItem<String> nodeC1 = new TreeItem<>("node C 1", new ImageView(icon));
  nodeA.getChildren().addAll(nodeA1,nodeB1,nodeC1);
  
  treeView.setRoot(root);
 }
 
 public void mouseClick(MouseEvent mouseEvent) {
  if (mouseEvent.getClickCount() == 2) {
  TreeItem<String> item = treeView.getSelectionModel().getSelectedItem();
  System.out.println(item.getValue());
  }
  
 }

}




<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
   <children>
      <TreeView fx:id="treeView" layoutX="59.0" layoutY="41.0" onContextMenuRequested="#mouseClick" onMouseClicked="#mouseClick" prefHeight="374.0" prefWidth="389.0" />
   </children>
</AnchorPane>






Thursday, November 12, 2015

C# - Connect To Cpanel MySql Database Remotely In C#









using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace MySqlConn
{
    public partial class Form1 : Form
    {
        MySqlConnection conn;
        string connString;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            connString = "SERVER= 127.0.0.1;PORT=3306;DATABASE=database_name;UID=user;PASSWORD=pass;";
            try
            {
                conn = new MySqlConnection();
                conn.ConnectionString = connString;
                conn.Open();
                MessageBox.Show("connection success");

                string query = "SELECT * FROM employee_data";
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, conn);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    Console.WriteLine(dataReader["id"] + "");
                    Console.WriteLine(dataReader["name"] + "");
                    Console.WriteLine(dataReader["surname"] + "");
                    Console.WriteLine(dataReader["age"] + "");
                }
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    }
}
















































Connect C# to MySQL
How to Connect to MySQL Using C#
c# - How to connect to MySQL Database?
MySQL .NET With C#
C# Windows Form Application Mysql Connection
c# - How can I connect to MySQL from windows forms?
Using Visual C# Windows Forms with MySQL
C# Programming for beginners: How to connect MySQL Database
Windows Form Application using Mysql Server 
Connect MySQL from C# Windows Forms 
mysql problem to connect with windows form c#
C# Windows Form Application Mysql Connection
Mysql And Visual C# 2010 Windows Form Application
MySQL :: Connecting to MySQL with a Windows Form application
C# Form textbox string into SQL Database
visual c# CLR windows form application and mysql
assembly reference not working in C# script
Trying to connect to MySQL from C# application 
mysql and C# window form application
How to connect MySQL using C#?‎
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ