Overview of GUI Development Using NetBeans and Java

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.


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