Overview of GUI Development Using NetBeans and Java

การเขียนโปรแกรมด้วย 
NetBeans
อาจารย์สมเกียรติ ช่อเหมือน
สาขาวิชาวิศวกรรมซอฟต์แวร์ คณะวิทยาศาสตร์และเทคโนโลยี
(tko@webmail
.
npru.ac.th)
เนื้อหาการเรียนรู้
NetBeans IDE
JAVA Platform
Framework in NetBeans
GUI Form 
ด้วย 
Jframe
AWT Event Listeners
JDBC API
https://www.slideshare.net/nkpandey01/jdbc-by-nitesh
NetBeans IDE
เน็ตบีนส์ (
NetBeans) 
เป็นเครื่องมือสำหรับนักโปรแกรมเมอร์ที่จะ
ใช้พัฒนา 
Application 
ด้วยภาษาจาวา
JAVA Platform
 
Framework in NetBeans
 
GUI Form 
ด้วย 
JFrame
Component Control 
การจัดวาง 
Layout 
ใน 
Frame
AWT (java.awt.Frame) 
Swing JFrame (javax.swing.JFrame)
https://www.ntu.edu.sg/home/ehchua/programming/java/j4a_gui.html
http://www2.hawaii.edu/~takebaya/ics111/inheritance/inheritance.html
javax.swing.JFrame
 
package com.java.myapp;
import javax.swing.JFrame;
public class  MyClass {
 
    public static void main(String[] args) {
        JFrame frame = new JFrame("A JFrame");
        frame.setSize(250, 250);
        frame.setLocation(300,200);
        frame.setVisible(true);
    }
}
https://www.thaicreate.com/java/java-gui-jframe.html
การสร้าง 
GUI Form
 
Visual Designer
 
ด้วย 
Component Controls
 
การปรับแต่งคุณสมบัติ
 
package
 
& import
package com.java.myapp;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.Font;
Create Form & Add Component
 
 
// Create Form Frame
  
super("ThaiCreate.Com Tutorial");
  
setSize(679, 385);
  
setLocation(500, 280);
  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
getContentPane().setLayout(null);
  
//Add Label Welcome
  
lblWelcome = new JLabel("lblWelcome",JLabel.CENTER);
  
lblWelcome.setFont(new Font("Tahoma", Font.PLAIN, 20));
  
lblWelcome.setBounds(168, 153, 336, 25);
  
getContentPane().add(lblWelcome);
  
// When Frame Event Loaded
  
addWindowListener(new WindowAdapter() {
   
@Override
   
public void windowOpened(WindowEvent e) {
    
LoginDialog();
   
}
  
});
Object Get & Set text
double water = Double.parseDouble(Input1.getText());
double elec = Double.parseDouble(Input2.getText());
double oil = Double.parseDouble(Input3.getText());
double rent = Double.parseDouble(Input4.getText());
double exp = Double.parseDouble(Input5.getText());
http://javanetbeansgui.blogspot.com/2009/12/java-4.html
lblResult.setText(String.valueOf(water + elec + oil + rent + exp));
AWT Event Listeners
java.util.EventListener
ActionListener
ComponentListener
ItemListener
KeyListener
MouseListener
TextListener
WindowListener
AdjustmentListener
ContainerListener
MouseMotionListener
FocusListener
https://www.nytimes.com/guides/smarterliving/be-a-better-listener
AwtListenerDemo.java
import java.awt.event.*;
okButton.addActionListener(new CustomActionListener());
 class CustomActionListener implements ActionListener{
      public void actionPerformed(ActionEvent e) {
         statusLabel.setText("Ok Button Clicked.");
      }
   }
JDBC API
DataSource object
Connection object
Statement, PreparedStatement, and
CallableStatement objects
ResultSet object
Connecting Database Using JDBC
 
public class JDBCUtil {
    String className, URL, user, password;
    Connection connection;
    public JDBCUtil(String className, String URL, String user, String password) {
        this.className = className;
        this.URL = URL;
        this.user = user;
        this.password = password;
        this.connection = null;
    }
    public void getConnection() {
        //Load the driver class
        try {
            Class.forName(className);
        } catch (ClassNotFoundException ex) {
            System.out.println("Unable to load the class. Terminating the program");
            System.exit(-1);
        }
        //get the connection
        try {
            connection = DriverManager.getConnection(URL, user, password);
        } catch (SQLException ex) {
            System.out.println("Error getting connection: " + ex.getMessage());
            System.exit(-1);
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
            System.exit(-1);
        }
    }
}
https://www.progress.com/blogs/jdbc-tutorial-connecting-to-your-database-using-jdbc
https://www.oracle.com/database/technologies/appdev/jdbc.html
Ex. Login Username 
และ 
Password
Connection connect = null;
PreparedStatement pre = null;
Boolean status = false;
Class.forName("com.mysql.jdbc.Driver");
connect =  DriverManager.getConnection("jdbc:mysql://localhost/mydatabase?user=root&password=root");
 
String sql = " SELECT * FROM  member WHERE Username = ?  AND Password = ? ";
 
pre = connect.prepareStatement(sql);
 
pre.setString(1, userName);
 
pre.setString(2, passWord);
 
ResultSet rec = pre.executeQuery();
 
if(rec.next()) {
 
    lblWelcome.setText("Welcome : " + rec.getString("Name"));
 
    status = true;
 
}
https://www.thaicreate.com/java/java-gui-example-login-username-password.html
Database Metadata via JDBC Driver
 
databaseMetaData = connection.getMetaData();
//Print TABLE_TYPE "TABLE"
R
e
s
u
l
t
S
e
t
 
r
e
s
u
l
t
S
e
t
 
=
 
d
a
t
a
b
a
s
e
M
e
t
a
D
a
t
a
.
g
e
t
T
a
b
l
e
s
(
n
u
l
l
,
 
n
u
l
l
,
 
n
u
l
l
,
 
n
e
w
 
S
t
r
i
n
g
[
]
{
T
A
B
L
E
}
)
;
System.out.println("Printing TABLE_TYPE \"TABLE\" ");
System.out.println("----------------------------------");
while(resultSet.next())
{
    //Print
    System.out.println(resultSet.getString("TABLE_NAME"));
}
https://www.progress.com/blogs/jdbc-tutorial-extracting-database-metadata-via-jdbc-driver
http://tutorials.jenkov.com/jdbc/resultset.html
Table Info
getTables(String catalog, String Schema, String
tableNamepattern, string type)
Column Info
getColumns(String Schema, String catalog, String
tableNamePattern, String ColumnNamePattern)
สรุปท้ายบท
ชุดเครื่อง 
NetBeans IDE 
สามารถพัฒนาบน 
JAVA Platform
ซึ่งมี 
Framework 
ในการพัฒนาโปรแกรม
การสร้าง 
GUI Form 
ด้วย 
Jframe 
และควบคุม
 
การโต้ตอบตามเหตุการณ์ด้วย 
AWT Event Listeners
การเชื่อมต่อฐานข้อมูลด้วยการใช้ 
JDBC API
การใช้คำสั่ง 
SQL 
และใช้งานผ่าน 
ResultSet
https://en.wikipedia.org/wiki/Event-driven_programming
Slide Note
Embed
Share

Explore the world of GUI development with NetBeans IDE and Java. Learn about building graphical user interfaces, utilizing event listeners, JDBC APIs, frameworks, and visual designers. Follow along with step-by-step instructions and visual examples to enhance your Java programming skills.

  • Java Programming
  • NetBeans IDE
  • GUI Development
  • Event Listeners
  • Visual Design

Uploaded on Sep 12, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. NetBeans (tko@webmail.npru.ac.th)

  2. NetBeansIDE JAVA Platform Framework in NetBeans GUI Form Jframe AWT Event Listeners JDBC API https://www.slideshare.net/nkpandey01/jdbc-by-nitesh

  3. NetBeans IDE (NetBeans) Application

  4. JAVA Platform

  5. Framework in NetBeans

  6. GUI Form JFrame Component Control Layout Frame AWT (java.awt.Frame) Swing JFrame(javax.swing.JFrame) https://www.ntu.edu.sg/home/ehchua/programming/java/j4a_gui.html http://www2.hawaii.edu/~takebaya/ics111/inheritance/inheritance.html

  7. javax.swing.JFrame packagecom.java.myapp; importjavax.swing.JFrame; publicclassMyClass { publicstaticvoidmain(String[] args) { JFrameframe = newJFrame("A JFrame"); frame.setSize(250, 250); frame.setLocation(300,200); frame.setVisible(true); } } https://www.thaicreate.com/java/java-gui-jframe.html

  8. GUI Form

  9. Visual DesignerComponent Controls

  10. package& import package com.java.myapp; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; import java.awt.Font;

  11. Create Form & Add Component // Create Form Frame super("ThaiCreate.Com Tutorial"); setSize(679, 385); setLocation(500, 280); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(null); //Add Label Welcome lblWelcome = new JLabel("lblWelcome",JLabel.CENTER); lblWelcome.setFont(new Font("Tahoma", Font.PLAIN, 20)); lblWelcome.setBounds(168, 153, 336, 25); getContentPane().add(lblWelcome); // When Frame Event Loaded addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { LoginDialog(); } });

  12. Object Get & Set text double water = Double.parseDouble(Input1.getText()); double elec = Double.parseDouble(Input2.getText()); double oil = Double.parseDouble(Input3.getText()); double rent = Double.parseDouble(Input4.getText()); double exp = Double.parseDouble(Input5.getText()); lblResult.setText(String.valueOf(water + elec+ oil + rent + exp)); http://javanetbeansgui.blogspot.com/2009/12/java-4.html

  13. AWT Event Listeners java.util.EventListener ActionListener ComponentListener ItemListener KeyListener MouseListener TextListener WindowListener AdjustmentListener ContainerListener MouseMotionListener FocusListener https://www.nytimes.com/guides/smarterliving/be-a-better-listener

  14. AwtListenerDemo.java import java.awt.event.*; okButton.addActionListener(new CustomActionListener()); class CustomActionListener implements ActionListener{ public void actionPerformed(ActionEvent e) { statusLabel.setText("Ok Button Clicked."); } }

  15. JDBC API DataSourceobject Connection object Statement, PreparedStatement, and CallableStatementobjects ResultSetobject

  16. Connecting Database Using JDBC public class JDBCUtil { String className, URL, user, password; Connection connection; public JDBCUtil(String className, String URL, String user, String password) { this.className = className; this.URL = URL; this.user = user; this.password = password; this.connection = null; } public void getConnection() { //Load the driver class try { Class.forName(className); } catch (ClassNotFoundException ex) { System.out.println("Unable to load the class. Terminating the program"); System.exit(-1); } //get the connection try { connection = DriverManager.getConnection(URL, user, password); } catch (SQLException ex) { System.out.println("Error getting connection: " + ex.getMessage()); System.exit(-1); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); System.exit(-1); } } } https://www.progress.com/blogs/jdbc-tutorial-connecting-to-your-database-using-jdbc https://www.oracle.com/database/technologies/appdev/jdbc.html

  17. Ex. Login Username Password Connection connect = null; PreparedStatementpre = null; Boolean status = false; Class.forName("com.mysql.jdbc.Driver"); connect = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase?user=root&password=root"); String sql= " SELECT * FROM member WHERE Username = ? AND Password = ? "; pre = connect.prepareStatement(sql); pre.setString(1, userName); pre.setString(2, passWord); ResultSetrec = pre.executeQuery(); if(rec.next()) { lblWelcome.setText("Welcome : " + rec.getString("Name")); status = true; } https://www.thaicreate.com/java/java-gui-example-login-username-password.html

  18. Database Metadata via JDBC Driver databaseMetaData = connection.getMetaData(); //Print TABLE_TYPE "TABLE" ResultSet resultSet = databaseMetaData.getTables(null, null, null, new String[]{ TABLE }); System.out.println("Printing TABLE_TYPE \"TABLE\" "); System.out.println("----------------------------------"); while(resultSet.next()) { //Print System.out.println(resultSet.getString("TABLE_NAME")); } https://www.progress.com/blogs/jdbc-tutorial-extracting-database-metadata-via-jdbc-driver http://tutorials.jenkov.com/jdbc/resultset.html

  19. Table Info getTables(String catalog, String Schema, String tableNamepattern, string type)

  20. Column Info getColumns(String Schema, String catalog, String tableNamePattern, String ColumnNamePattern)

  21. NetBeansIDE JAVA Platform Framework GUI Form Jframe AWT Event Listeners JDBC API SQL ResultSet https://en.wikipedia.org/wiki/Event-driven_programming

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#