RSS
Təsvir

1.Java Swing JTable doldurmaq MySql ilə

1.ctreate table in mysql

create table invertar.Example(
id int auto_increment Primary Key,
name varchar(30),
birthday Date,
status varchar(1)  //sonra bize lazimolar..
)

  1. java  example classimizi yaradırıq.

package az;

import java.util.Date;

/**
*
* @author AqilI
*/

public class Example {
private int id;
private String name;
private Date birthday;
private String status;

public Example() {
}

public Example(int id, String name, Date birthday,String status) {
this.id = id;
this.name = name;
this.birthday = birthday;
this.status=status;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

}

3.Connection classımızı yaradaq.    // proyektə  mysq jar file əlavə etməyi unutmayin))

import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import logn.Login;

/**
*
* @author AqilI
*/
public class Connection {

private static java.sql.Connection conn = null;
private static PreparedStatement psate = null;
private static ResultSet rs = null;
private static final String user = “root”;
private static final String password = “sizin şifrə“;
private static final String url = “mysql url“;

public static void connection() throws SQLException {
try {
Class.forName(“com.mysql.jdbc.Driver”);
conn = DriverManager.getConnection(url, user, password);

} catch (ClassNotFoundException e) {
System.out.println(“Driver tapilmadi: ” + ” ” + e.getMessage());
e.printStackTrace();
}
}

public static void closed() {
try {
if (conn != null) {
conn.close();
}
if (psate != null) {
psate.close();
}
} catch (Exception e) {
System.out.println(“Connection Baglanmadi! ” + e.getMessage());
e.printStackTrace();
}
}

//listlə doldururuq

public List<Example> allExample() throws Exception {
try {
connection();
List<Example> exmple = new ArrayList<>();
String sql = “select * from invertar.example“;
psate = conn.prepareStatement(sql);
rs = psate.executeQuery();
while (rs.next()) {
Example e = new Example();
e.setId(rs.getInt(1));
e.setName(rs.getString(2));
e.setBirthday(rs.getDate(3));

exmple .add(e);

}
return exmple ;
} catch (SQLException sql) {
System.out.println(“Xeta: ” + sql.getMessage());
sql.printStackTrace();
return null;
} finally {
closed();
}
}

//table header

public List<String> headerExample() {
List<String> head = new ArrayList<String>();
head.add(“Id”);
head.add(“Name”);
head.add(“Birthday”);
return head;
}

}

4.Table model classimizi yaradaq.

package az;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
*
* @author AqilI
*/
public class ExampleTableModel extends AbstractTableModel {

private List<Example> list;
private List<String> head;

public ExampleTableModel(List<Example> list, List<String> head) {
this.list = list;
this.head = head;
}

@Override
public String getColumnName(int column) {
return head.get(column);
}

@Override
public int getRowCount() {
return list.size();
}

@Override
public int getColumnCount() {
return head.size();
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return list.get(rowIndex).getId();
} else if (columnIndex == 1) {
return list.get(rowIndex).getName();
} else {
return list.get(rowIndex).getBirthday();
}
}
}

  1. jframe Table form

package az;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ListSelectionModel;

/**
*
* @author AqilI
*/
public class ExampleTable extends javax.swing.JFrame {

final Connection con = new Connection();
final Example e = new Example();

public ExampleTable() {
try {
initComponents();
setLocationRelativeTo(this);
setTitle(“Example Table from“);
refleshTbModel();
tbExample.setShowGrid(true);
tbExample.setSelectionForeground(Color.RED);
tbExample.setSelectionBackground(Color.LIGHT_GRAY);
tbExample.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tbExample.setRowHeight(20);
tbExample.setRowSelectionAllowed(true);
this.pack();

} catch (Exception ex) {
Logger.getLogger(ExampleTable.class.getName()).log(Level.SEVERE, null, ex);
}
}

public void refleshTbModel() throws Exception {
ExampleTableModel table_Model = new ExampleTableModel(con.allExample(), con.headerExample());
tbExample.setModel(table_Model);

}

@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
tbExample = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jScrollPane1.setViewportView(tbExample);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(14, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
/
public static void main(String args[]) {
/
Set the Nimbus look and feel /
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/
If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ExampleTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ExampleTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ExampleTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ExampleTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ExampleTable().setVisible(true);
}
});
}

// Variables declaration – do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tbExample;
// End of variables declaration
}

 

table

\ davami olaraq insert, delete, update ,search və jogin page hissələrini paylaşmağacçalışaram.

 
Bir şərh yazın

Müəllif Açıq 27 Noyabr 2016 in SWİNG

 

Jframe full screen size açılması

Bəzən Jframe’lərdə elə problem qarşılaşırıq ki, biz öz komputerimizin ölçülərinə uyğun  ölçü veririk ama manitoru fərqli komputerlərdə çalışdırdığımız zamanı  dizayn pozğunluğu yaranır.
bunun həlli aşağıda göstərmişəm ,yəni hər run zamani  həmin komputer manitorunun fullScreen size ölçülərinə uyğun açılır..

 

package itmim.view;

import java.awt.Toolkit;

/**
*
* @author AqilI
*/
public class FullScren extends javax.swing.JFrame {

Toolkit tk = Toolkit.getDefaultToolkit();
public int WindowWidth = (int) tk.getScreenSize().getWidth();
public int WindowHeight = (int) tk.getScreenSize().getHeight();

public FullScren() {
initComponents();
setLocationRelativeTo(this);
this.setSize(WindowWidth, WindowHeight);
this.setLocation(0, 0);
}
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(() -> {
new FullScren().setVisible(true);
});
}

// Variables declaration – do not modify
// End of variables declaration
}

 
Bir şərh yazın

Müəllif Açıq 27 Noyabr 2016 in SWİNG

 

TextField-i numeric formata qoymaq

əgər textField’ə ancaq rəqəm tipinin daxil edliməsini lazim gəlsə

həmin textField’in  üstünə sağ tıklayib   Events>Key>KeyPressed actionuna aşağıdakı kodu yazmaq lazım

2016-11-27_024756

private void txtNumberFormatKeyPressed(java.awt.event.KeyEvent evt) {

{
int key = evt.getKeyCode();
if ((key >= evt.VK_0 && key <= evt.VK_9) || (key >= evt.VK_NUMPAD0 && key <= evt.VK_NUMPAD9) || key == KeyEvent.VK_BACK_SPACE) {
txtNumberFormat.setForeground(Color.GREEN);
} else {
JOptionPane.showMessageDialog(rootPane, “Yalnız rəqəm tipində daxil edin!”);
txtNumberFormat.setText(“”);
}
}

əgər rəqəm  tipindən fərqli tipdaxil edilərsə
}eeee

rəqəm tipi daxil edilərsə:

rrr

Uğurlar:)

 
1 Şərh

Müəllif Açıq 27 Noyabr 2016 in SWİNG

 

java encryption decryption

1.

package az;

import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
*
* @author AqilI
*/
public class AESencrp {

private static final String ALGO = “AES”;
private static final byte[] keyValue = new byte[]{‘T’, ‘h’, ‘e’, ‘B’, ‘e’, ‘s’, ‘t’,
‘S’, ‘e’, ‘c’, ‘r’, ‘e’, ‘t’, ‘K’, ‘e’, ‘y’};

public static String encrypt(String Data) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encVal = c.doFinal(Data.getBytes());
String encryptedValue = new BASE64Encoder().encode(encVal);
return encryptedValue;
}

public static String decrypt(String encryptedData) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGO);
c.init(Cipher.DECRYPT_MODE, key);
byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
byte[] decValue = c.doFinal(decordedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
}

private static Key generateKey() throws Exception {
Key key = new SecretKeySpec(keyValue, ALGO);
return key;
}
}

 

 

2.

package az;

/**
*
* @author AqilI
*/
public class Checker {

public static void main(String[] args) throws Exception {

String password = “1”;
String my=”kmj7cdKWic9Ivr3IBofjNA==”;
String passwordEnc = AESencrp.encrypt(password);
String passwordDec = AESencrp.decrypt(passwordEnc);

System.out.println(“Plain Text : ” + password);
System.out.println(“Encrypted Text : ” + passwordEnc);
System.out.println(“Decrypted Text : ” + passwordDec);
System.out.println(“password:: ” + my);
}
}

Result:

Plain Text : 1
Encrypted Text : kmj7cdKWic9Ivr3IBofjNA==
Decrypted Text : 1
—————–
My Password:):: kmj7cdKWic9Ivr3IBofjNA==
BUILD SUCCESSFUL (total time: 0 seconds)

 

 

 
Bir şərh yazın

Müəllif Açıq 27 Noyabr 2016 in Java SE

 

info

  1. Java Programlama blogum zaman zaman bildiklərimi paylaşmağa çalışaram…
 
5 Şərh

Müəllif Açıq 14 Noyabr 2014 in Java SE

 
 
%d bloqqer bunu bəyənir: