This one is a coat hanger walker based on the book “Absolute Beginners Guide in Building Robot’s” by Gareth Branwyn.
And here's another very simple BEAM walking robot made from old toy gears. Enjoy :D
/*imports the required packages*/
import javax.swing.*;
import java.awt.*;
import java.sql.*;
/*Creates a class named UseJDBC. extends JFrame means that UseJDBC is not just some class
it's also a Frame */
public class UseJDBC extends JFrame
{
/* Create a container named ca.*/
Container ca=getContentPane();
/* Create a borderlayout which will be used later to position our panel1
on the north portion of the container*/
BorderLayout border=new BorderLayout(2,2);
/* Create a gridlayout with 3 rows and 2 columns.
Will be used to arrange our labels and textfields in a grid format*/
GridLayout grid=new GridLayout(3,2,1,1);
/*Create a panel named panel1. this is where we will add our controls later*/
JPanel panel1=new JPanel();
/*Creates our textboxes where we want o display our records later*/
JTextField IDtextbox=new JTextField();
JTextField Fnametextbox=new JTextField();
JTextField Lnametextbox=new JTextField();
public UseJDBC()
{
/*Applies the borderlayout to our container*/
ca.setLayout(border);
/*Applies the gridlayout to our panel*/
panel1.setLayout(grid);
/*Add our controls to the panel*/
panel1.add(new JLabel("ID:"));
panel1.add(IDtextbox);
panel1.add(new JLabel("Firstname:"));
panel1.add(Fnametextbox);
panel1.add(new JLabel("Lastname:"));
panel1.add(Lnametextbox);
/*Adds the panel to our container and position it to the north(top)
* portion of the container
*/
ca.add(panel1,BorderLayout.NORTH);
/*Setup our frame*/
setContentPane(ca);
setSize(294,155);
setLocation(0,0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("View Records");
setVisible(true);
/* Creates a connection object named connectionobj*/
Connection connectionobj;
try {
/*Creates a new instance of our jdbc driver*/
Class.forName("com.mysql.jdbc.Driver").newInstance();
/*Connect to our database named dbNames using the
username dbusername and password dbpassword*/
connectionobj = DriverManager.getConnection( "jdbc:mysql://localhost:3306/dbNames","dbusername","dbpassword");
/*Create a statement object named statementobj*/
Statement statementobj = connectionobj.createStatement() ;
/*Specify how we want to retrieve the record from MySQL Workbench
* by using the executeQuery method of our statement object. Since we want all records from
* all columns so we entered "Select * from tblNames" as a sql statement
* The resultset will be stored in a variable named resultSet
*/
ResultSet resultSet = statementobj.executeQuery( "SELECT * From tblNames" ) ;
/*Points the record pointer to the first record*/
resultSet.first( );
/*Retrieve the values of each fieldname or columns and store it to our local variables*/
String strid = Integer.toString(resultSet.getInt("intid"));
String strfname = resultSet.getString("chrfname");
String strlname = resultSet.getString("chrlname");
/*Display our first records on their appropriate controls*/
IDtextbox.setText(strid);
Fnametextbox.setText(strfname);
Lnametextbox.setText(strlname);
/*Close the database connection*/
connectionobj.close() ;
}
catch (Exception e)
{
}
}
/* Creates our main method*/
public static void main (String[] args)
{
UseJDBC UseJDBCinstance=new UseJDBC();
}
}
import javax.swing.*;
import java.awt.*;
import java.sql.*;
public class UseJDBC extends JFrame
{
Container ca=getContentPane();
BorderLayout border=new BorderLayout(2,2);
GridLayout grid=new GridLayout(3,2,1,1);
JPanel panel1=new JPanel();
JTextField IDtextbox=new JTextField();
JTextField Fnametextbox=new JTextField();
JTextField Lnametextbox=new JTextField();
public UseJDBC()
{
ca.setLayout(border);
panel1.setLayout(grid);
panel1.add(new JLabel("ID:"));
panel1.add(IDtextbox);
panel1.add(new JLabel("Firstname:"));
panel1.add(Fnametextbox);
panel1.add(new JLabel("Lastname:"));
panel1.add(Lnametextbox);
ca.add(panel1,BorderLayout.NORTH);
setContentPane(ca);
setSize(294,155);
setLocation(0,0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("View Records");
setVisible(true);
Connection connectionobj;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connectionobj = DriverManager.getConnection( "jdbc:mysql://localhost:3306/dbNames","dbusername","dbpassword");
Statement statementobj = connectionobj.createStatement() ;
ResultSet resultSet = statementobj.executeQuery( "SELECT * From tblNames" ) ;
resultSet.first( );
String strid = Integer.toString(resultSet.getInt("intid"));
String strfname = resultSet.getString("chrfname");
String strlname = resultSet.getString("chrlname");
IDtextbox.setText(strid);
Fnametextbox.setText(strfname);
Lnametextbox.setText(strlname);
connectionobj.close() ;
}
catch (Exception e)
{
}
}
public static void main (String[] args)
{
UseJDBC UseJDBCinstance=new UseJDBC();
}
}