වැඩ්ඩනි පොඩි help එකක් ඕනි
JAVA
ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.
![]()
Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.
![]()
මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.
දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවදCode:void loadcomboCatInv(){ try { ResultSet rs = db.getData("SELECT cat_name FROM itemcategory"); Vector v = new Vector(); while(rs.next()){ v.add(rs.getString("cat_name")); comboCatInv.setModel(new DefaultComboBoxModel(v)); }![]()
වැඩ්ඩනි පොඩි help එකක් ඕනි
........................................
Item Cගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද![]()
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Compare extends JFrame implements ItemListener {
JComboBox combo, lcombo;
public Compare() {
setLayout(null);
String a[] = { "Select", "Watches", "Mobiles", "shoes" };
combo = new JComboBox(a);
combo.setBounds(50, 50, 100, 20);
combo.addItemListener(this);
add(combo);
lcombo = new JComboBox();
lcombo.addItemListener(this);
lcombo.setEnabled(false);
add(lcombo);
lcombo.setBounds(50, 100, 100, 20);
setSize(300, 300);
}
public void itemStateChanged(ItemEvent e) {
String b[] = { "Titan", "HMT" };
String c[] = { "Nokia", "Sony", "Motorola", "Samsung" };
String d[] = { "Liberty", "Action", "Bata", "Campus", "Relaxo" };
if (e.getSource() == combo) {
if (combo.getSelectedItem().equals("Select")) {
lcombo.setEnabled(false);
} else if (combo.getSelectedItem().equals("Watches")) {
lcombo.setEnabled(true);
lcombo.removeAllItems();
for (int i = 0; i < b.length; i++) {
lcombo.addItem(b[i]);
}
} else if (combo.getSelectedItem().equals("Mobiles")) {
lcombo.setEnabled(true);
lcombo.removeAllItems();
for (int i = 0; i < c.length; i++) {
lcombo.removeItem(c[i]);
lcombo.addItem(c[i]);
}
} else if (combo.getSelectedItem().equals("shoes")) {
lcombo.setEnabled(true);
lcombo.removeAllItems();
for (int i = 0; i < d.length; i++) {
lcombo.addItem(d[i]);
}
}
}
}
public static void main(String args[]) {
(new Compare()).setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class ComboBoxTwo extends JFrame implements ActionListener
{
private JComboBox mainComboBox;
private JComboBox subComboBox;
private Hashtable subItems = new Hashtable();
public ComboBoxTwo()
{
String[] items = { "Select Item", "Color", "Shape", "Fruit" };
mainComboBox = new JComboBox( items );
mainComboBox.addActionListener( this );
// prevent action events from being fired when the up/down arrow keys are used
// mainComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
getContentPane().add( mainComboBox, BorderLayout.WEST );
// Create sub combo box with multiple models
subComboBox = new JComboBox();
subComboBox.setPrototypeDisplayValue("XXXXXXXXXX"); // JDK1.4
getContentPane().add( subComboBox, BorderLayout.EAST );
String[] subItems1 = { "Select Color", "Red", "Blue", "Green" };
subItems.put(items[1], subItems1);
String[] subItems2 = { "Select Shape", "Circle", "Square", "Triangle" };
subItems.put(items[2], subItems2);
String[] subItems3 = { "Select Fruit", "Apple", "Orange", "Banana" };
subItems.put(items[3], subItems3);
mainComboBox.setSelectedIndex(1);
}
public void actionPerformed(ActionEvent e)
{
String item = (String)mainComboBox.getSelectedItem();
Object o = subItems.get( item );
if (o == null)
{
subComboBox.setModel( new DefaultComboBoxModel() );
}
else
{
subComboBox.setModel( new DefaultComboBoxModel( (String[])o ) );
}
}
public static void main(String[] args)
{
JFrame frame = new ComboBoxTwo();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
}
මට හිතෙන විදියටකියන්නම්..වැඩ්ඩනි පොඩි help එකක් ඕනි
JAVA
ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.
![]()
Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.
![]()
මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.
දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවදCode:void loadcomboCatInv(){ try { ResultSet rs = db.getData("SELECT cat_name FROM itemcategory"); Vector v = new Vector(); while(rs.next()){ v.add(rs.getString("cat_name")); comboCatInv.setModel(new DefaultComboBoxModel(v)); }![]()
බලන්න මේක හරියනවද කියල.HELP BUMP!!![]()
import java.util.Arrays;
import java.util.Objects;
/**
*
* @author MihiCherub
*/
public class Skaters {
private String name1;
private String name2;
private String country;
private double[] arrTech = new double[8];
private double[] arrPerf = new double[8];
private double score;
public Skaters() {
}
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
this.name2 = name2;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public double[] getArrTech() {
return arrTech;
}
public void setArrTech(double[] arrTech) {
this.arrTech = arrTech;
}
public double[] getArrPerf() {
return arrPerf;
}
public void setArrPerf(double[] arrArt) {
this.arrPerf = arrArt;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
@Override
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (getClass() != object.getClass()) {
return false;
}
final Skaters other = (Skaters) object;
return this.hashCode() == other.hashCode();
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.name1);
hash = 71 * hash + Objects.hashCode(this.name2);
hash = 71 * hash + Objects.hashCode(this.country);
hash = 71 * hash + Arrays.hashCode(this.arrTech);
hash = 71 * hash + Arrays.hashCode(this.arrPerf);
hash = 71 * hash + (int) (Double.doubleToLongBits(this.score) ^ (Double.doubleToLongBits(this.score) >>> 32));
return hash;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
* @author MihiCherub
*/
public class SkaterRecords {
private final List<Skaters> list;
public SkaterRecords() {
list = new ArrayList<Skaters>();
}
public boolean addRecord(Skaters skaters) {
return list.add(skaters);
}
public int getTotalRecords() {
return list.size();
}
public void removeAllFrom(int index) {
//Captures the beginning of where u specify 'index' to the end and clears it
list.subList(index, list.size()).clear();
}
public void removeAllUpto(int index) {
//Captures the beginning '0' up to where u specify 'index' and clears it
list.subList(0, index).clear();
}
public void printRecord() {
for (Skaters skater : list) {
System.out.println("Name1: " + skater.getName1());
System.out.println("Name2: " + skater.getName2());
System.out.println("Country: " + skater.getCountry());
double[] arrTech = skater.getArrTech();
for (double value : arrTech) {
System.out.print(value + " ");
}
System.out.println("");
double[] arrPerf = skater.getArrPerf();
for (double value : arrPerf) {
System.out.print(value + " ");
}
System.out.println("");
System.out.println("Score: " + skater.getScore());
System.out.println("");
}
}
public Skaters getWinner() {
double max = 0;
Skaters winner = null;
for (Skaters skater : list) {
if (max < skater.getScore()) {
max = skater.getScore();
winner = skater;
}
}
return winner;
}
@Override
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (getClass() != object.getClass()) {
return false;
}
final SkaterRecords other = (SkaterRecords) object;
return this.hashCode() == other.hashCode();
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.list);
return hash;
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author MihiCherub
*/
public class TestSkaters {
private static SkaterRecords skaterRecords;
public static void main(String[] args) throws FileNotFoundException {
skaterRecords = new SkaterRecords();
readFile();
skaterRecords.printRecord();
Skaters winner = skaterRecords.getWinner();
System.out.println("Medal Winners :");
System.out.println("Name1: " + winner.getName1());
System.out.println("Name2: " + winner.getName2());
System.out.println("Country: " + winner.getCountry());
System.out.println("Score: " + winner.getScore());
}
private static void readFile() throws FileNotFoundException {
File file = new File("Pairs.txt");
Scanner input;
if (file.exists()) { // FileNotFoundException Handle
input = new Scanner(file);
while (input.hasNext()) {
Skaters skater = new Skaters();
skater.setName1(input.nextLine());
skater.setName2(input.nextLine());
skater.setCountry(input.nextLine());
double sum = 0;
final double tech[] = new double[8];
for (int i = 0; i < 8; i++) {
tech[i] = input.nextDouble();
sum += tech[i];
}
skater.setArrTech(tech);
final double perf[] = new double[8];
for (int i = 0; i < 8; i++) {
perf[i] = input.nextDouble();
sum += perf[i];
}
skater.setArrPerf(perf);
skater.setScore(sum / 2);
skaterRecords.addRecord(skater);
if (input.hasNextLine()) {
input.nextLine();
}
}
try {
} finally {
input.close();
}
}
}
}

වැඩ්ඩනි පොඩි help එකක් ඕනි
JAVA
ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.
![]()
Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.
![]()
මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.
Code:void loadcomboCatInv(){ try { ResultSet rs = db.getData("SELECT cat_name FROM itemcategory"); Vector v = new Vector(); while(rs.next()){ v.add(rs.getString("cat_name")); comboCatInv.setModel(new DefaultComboBoxModel(v)); }
දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද![]()
thilihare
KingCM
MihiCherub
අනේ Thanks මචන්ලා මම try එකක් දීල බලල කියන්නම්. Thanks a lot
int row = JtableCat.getSelectedRow();
String selectedCat = JtableCat.getModel().getValueAt(row,0).toString();
//CatName to CatID Query
ResultSet rsCatNameToId = db.getData(("SELECT cat_id FROM itemcategory WHERE cat_name='"+selectedCat+"'"));
while (rsCatNameToId.next()) {
int theCatId = rsCatNameToId.getInt("cat_id");
//Main Search Query
ResultSet rsCat = db.getData("SELECT * FROM items WHERE itemCategory_cat_id='"+theCatId+"'");
DefaultTableModel dtmItems = (DefaultTableModel) JtitemTable.getModel();
dtmItems.setRowCount(0);
while (rsCat.next()){
Vector vItem = new Vector();
vItem.add(rsCat.getString("item_name"));
vItem.add(rsCat.getString("item_qty"));
dtmItems.addRow(vItem);
}
}
මේ Query 1 මම උඩ එහෙන් පිටින්ම දීල තියෙනව දැක්කෙ නැතෙයි,
වැඩේ ගොඩ දාගත්ත මචන්. යන්තන් query එක ලියාගත්තා. දුකේ බෑ බන් වැඩ කරනවා ලෙසටම.
MihiCherub thanks මචන් අතන මම table එකට වැඩිපුර field එකක් දාල මචන්. මට ඔයා කිවුවම තමයි මීටර් උනේ. ඒ table එකේ තියන අන්තිම field එකක මම FK කරල දාලා තිබුනෙ. දැන් වැඩේ හරි
Query එක මීට වඩා අඩුවෙන් ලියන්න පුලුවන් ක්රමයක් තියෙනවද. මේ query එකෙන් නම් ඕන කරන result එක එනවා
Code:int row = JtableCat.getSelectedRow(); String selectedCat = JtableCat.getModel().getValueAt(row,0).toString(); //CatName to CatID Query ResultSet rsCatNameToId = db.getData(("SELECT cat_id FROM itemcategory WHERE cat_name='"+selectedCat+"'")); while (rsCatNameToId.next()) { int theCatId = rsCatNameToId.getInt("cat_id"); //Main Search Query ResultSet rsCat = db.getData("SELECT * FROM items WHERE itemCategory_cat_id='"+theCatId+"'"); DefaultTableModel dtmItems = (DefaultTableModel) JtitemTable.getModel(); dtmItems.setRowCount(0); while (rsCat.next()){ Vector vItem = new Vector(); vItem.add(rsCat.getString("item_name")); vItem.add(rsCat.getString("item_qty")); dtmItems.addRow(vItem); } }
නෝමලි ResultSet, Vector වගේ ඒවට වෙන නම් දාන්න යන්න එපා. form එකටම එකනෙ තියෙන්නෙ. ඒ නිසා ResultSet rs = ...; Vector v = ...; කියල use කරන්න. ඒක කෝඩ් එක පස්සෙ බලනකොට මාර ලේසියි.අවුලක් තියෙනව නම් අහන්න.[/SIZE]![]()


String userName = txtuname.getText();
String userType;
if (JrAdmin.isSelected()) {
userType = "Admin";
} else if (JrCash.isSelected()) {
userType = "Cashier";
}else userType = "Owner";
db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");
String uname = txtUserName.getText();
String pass = new String(txtPassword.getPassword());
ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+pass+"'");
if(userset.next()) {
dispose();
new mainUI().setVisible(true);

මචන්ලා
Java වලින් login form එකක් හදද්දි මං ඒකට පාවිච්චි කලේ JPasswordField එකක්. Db එකේ plain text වලින් password එක store කරන් නැති වෙන්න ඕන නිසා. save කලාම db එකේ encrypt වෙච්ච code එකක් වගේ මෙව්වා එකක් විදියට password එක save වෙනවා. ඒත් මම login form එකේ log වෙන code එකට password compare කරන්න try කලාට කරගන්න බෑනෙ. පොඩි help එකක් දෙනවද
user ව save කරන code එක මම ලිවුවෙ මෙහෙම
Code:String userName = txtuname.getText(); String userType; if (JrAdmin.isSelected()) { userType = "Admin"; } else if (JrCash.isSelected()) { userType = "Cashier"; }else userType = "Owner"; db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");
login code එක මෙහෙම
Code:String uname = txtUserName.getText(); String pass = new String(txtPassword.getPassword()); ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+pass+"'"); if(userset.next()) { dispose(); new mainUI().setVisible(true);
database එකේ password එකට යන data type එක VARCHAR වලට දැම්මොත් නම් ඔය code එක වැඩ කරනවා. ඒත් plain text තියන එක අවුල් නිසා එකට මොකද්ද මචන්ලා කරන්න ඕන. database එකේ password එක තියන්න හොද මොන data type එකෙන්ද![]()
oka encrypt karala newei db ekata yanne. char[] array ekak widiyata. mysql database eke password ekata deela thiyena data type eka mokakd?
Harinam password eka db ekata sha-256 ekakin salt ekak ekka hash karala thamai yawanne.


VARCHAR තමයි මචෝ තියෙන්නේ.
password එක compare කරන්න ඕන code එක යන්තන් කියන්න පුලුවන්ද
- user කෙනෙක් create කරන තැනයි
- Login form එකෙයි
අනිත් ටික නම් අටවගන්න පුලුවන්![]()
db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+new String(txtupass.getPassword())+"')");
save karana thena meka wenas karala balanna.
Code:db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+new String(txtupass.getPassword())+"')");


db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");
දැන් තියෙන ඩේටා ටයිප් එක මොකද්ද?database එකේ password එකට යන data type එක VARCHAR වලට දැම්මොත් නම් ඔය code එක වැඩ කරනවා. ඒත් plain text තියන එක අවුල් නිසා එකට මොකද්ද මචන්ලා කරන්න ඕන. database එකේ password එක තියන්න හොද මොන data type එකෙන්ද![]()
user id එකක් අවශ්ය නොවේ. user name එක unique නිසා ඒක තමයි primary key එක වෙන්නෙ.එහෙම කලාම මෙන්න මේ 4 වෙනි ID එකේ තියෙන විදියට save උනේ මචන්
![]()
අනිත් ID වල තියෙන විදියට password save වෙනවා මේ යටින් තියෙන විදියට දැම්මම. ඒත් ඒක ආයෙ user ව log කරන තැනද compare කරගන්න ගියාම අවුල් වෙනවනෙ
------------Code:db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");
මේ තියේනනේ මගේ user table එක
![]()
String uname = txtUserName.getText();
ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+txtPassword.getPassword()+"'");
if(userset.next()) {
dispose();
new mainUI().setVisible(true);
}
user id එකක් අවශ්ය නොවේ. user name එක unique නිසා ඒක තමයි primary key එක වෙන්නෙ.
login code එක මෙහෙම දාන්න.
Code:String uname = txtUserName.getText(); ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+txtPassword.getPassword()+"'"); if(userset.next()) { dispose(); new mainUI().setVisible(true); }
