Search Your Question

Monday, August 10, 2009

AJAX Call from JavaScript in Java

if(window.XMLHttpRequest)//non IE
{
    req = new XMLHttpRequest();
    try
    {
         req.open("GET",url,true);
         req.onreadystatechange=setInTextField;
    }
    catch(e)
    {
         alert("cannot connect to server");
    }
    req.send(null);
}
else if(window.ActiveXObject)//IE
{
    try
    {
         req=new ActiveXObject("Msxml2.XMLHTTP.3.0");
    }
    catch(e)
    {
         req=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if(req)
    {
         req.open("GET",url,true);
         req.onreadystatechange=setInTextField;
         req.send(null);
    }
}

Friday, July 24, 2009

Disable any element in a HTML page by JavaScript



document.getElementById('id').disabled=true;

Tuesday, July 21, 2009

JavaScript Text Field formatter for input money

function moneyonly(e)
{
    var unicode=e.charCode? e.charCode : e.keyCode;
    var st = document.getElementById("amount").value;
//alert(unicode)
    if (unicode== 8)
    {
        return true;
//if the key isn't the backspace key (which we should allow)
    }
    else if(unicode == 46)
    {

        if(st.toString().indexOf(".",0) != -1)
        {
            return false;
        }

    }
    else if (unicode<48||unicode>57) //if not a number
    {

        return false //disable key press
    }
    else if(st.toString().indexOf(".",0) != -1)
    {
        if(st.toString().length - st.toString().indexOf(".",0) > 2)
        {
            return false;
        }
    }

    return true;
}

Trim function in JavaScript

function trimThis(value1)
{
    value1= value1.replace(/^\s+|\s+$/, '');
    return value1;
}

Friday, June 5, 2009

Set Image Background in a JPanel

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.swing.*;

public class BackgroundImage {
public static void main(String[] args) throws IOException {
BufferedImage image = javax.imageio.ImageIO.read(new File("C:\\WINDOWS\\Web\\Wallpaper\\Azul.jpg"));
ImageBackgroundPanel imp = new ImageBackgroundPanel(image);

// Set layout and add components to imp as desired.

JFrame f = new JFrame();
JTextField txtField=new JTextField(20);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(imp);
imp.add(txtField);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}

class ImageBackgroundPanel extends JPanel {
BufferedImage image;

ImageBackgroundPanel(BufferedImage image) {
this.image = image;
}

protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
}
}

Tuesday, June 2, 2009

Send mail through JAVA with attachment.

For run this code you should download mail.jar

http://mirrors.ibiblio.org/pub/mirrors/maven/ant/jars/ant-javamail-1.6.jar

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class Main
{
 public static void main (String args[]) throws Exception
  {
   String host = "mail.xyz.com"; //Host name should be some mail host name
   String from = "sounak@xyz.com"; // form address
   String to = "sounak@xyz.com"; // to address
   String fileAttachment = "d:\\sqljdbc.jar"; // file path
// Get system properties
   Properties props = System.getProperties();
// Setup mail server
   props.put("mail.smtp.host", host);
// Get session
   Session session = Session.getInstance(props, null);
// Define message MimeMessage message = new MimeMessage(session); message.setFrom( new InternetAddress(from));
   message.addRecipient( Message.RecipientType.TO, new InternetAddress(to));
   message.setSubject( "Hello JavaMail Attachment");
// create the message part
   MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
   messageBodyPart.setText("Hi");
   Multipart multipart = new MimeMultipart();
   multipart.addBodyPart(messageBodyPart);
// Part two is attachment
   messageBodyPart = new MimeBodyPart();
   DataSource source = new FileDataSource(fileAttachment);
   messageBodyPart.setDataHandler( new DataHandler(source));
   messageBodyPart.setFileName(fileAttachment);
   multipart.addBodyPart(messageBodyPart);
// Put parts in message
   message.setContent(multipart);
// Send the message
   Transport.send( message );
  }
}

Tuesday, May 19, 2009

Generate new ID from a database table in java

/*
* This is the class which create a new Unique ID for a database Table.
* It takes three Parameter.
* tableName is used to take the database name
* prefix is used for attach the prefix to the generated ID.
* columnName is the name of the column of the table.
*/

import java.sql.ResultSet;
import java.sql.Statement;
import model.connection.connection;

/**
*
* @author Arnab
*/
public class IdGenerator
{
private String next_id;

public String getNextId(String tableName,String prefix,String columnName)
{
connection con=new connection(); //create the connection of database.
try
{
int temp=0;
Statement stmt=con.getCon().createStatement(); // getCon() is the return type of created Connection.
ResultSet rs=stmt.executeQuery("select "+columnName+" from "+tableName);
while(rs.next())
{
String t_code_temp=rs.getString(1).trim();
int code=Integer.parseInt(t_code_temp.substring(t_code_temp.indexOf(prefix)+prefix.length()));
if(code>temp)
{
temp=code;
}
}

next_id=prefix+(++temp);
}
catch(Exception e)
{
ExceptionLogger.writeToFile(this.getClass().getName()+": "+e); //This is the file where Exceptions are stored.
}
return next_id;
}

Save exception in a log file.

//This is a static function to save the exception in a file.

public static boolean writeToFile(String text)
{
Date recentdate=Calendar.getInstance().getTime();
logger=new File("C:\\File_Name.txt");
try {
FileWriter fw = new FileWriter(logger, true);
fw.write("\n"+recentdate+": "+text);
fw.flush();
fw.close();
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, ex);
return false;
}

return true;
}

//This is the process to save the exception

ExceptionLog.writeToFile(this.getClass().getName()+": "+e);

Friday, May 8, 2009

Free Download Java/JSP Ebooks.

Visit:

http://www.flazx.com

Tuesday, April 28, 2009

Set Icon in Mouse Pointer by Javascript

//Set Icon in Mouse Pointer by Javascript
function initToolTips()
{
if(document.getElementById)
{
toolTipSTYLE = document.getElementById("toolTipLayer").style;
}
if(is_ie is_nav6up)
{
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
document.onmousemove = moveToMousePos;
}
}
function moveToMousePos(e)
{
if(!is_ie)
{ x = e.pageX; y = e.pageY; }
else
{ x = event.x + document.body.scrollLeft; y = event.y + document.body.scrollTop;
}
toolTipSTYLE.left = x + offsetX+'px';
toolTipSTYLE.top = y + offsetY+'px';
return true;
}
function hide()
{ if(is_nav4) toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
}
function show()
{ toolTip(s);
}
function toolTip(msg, fg, bg)
{
if(toolTip.arguments.length < 1)
// if no arguments are passed then hide the tootip
{ if(is_nav4)
toolTipSTYLE.visibility = "hidden";
else toolTipSTYLE.display = "none";
} else
// show { var content = msg; if(is_nav4)
{ toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible"; }
else if(is_ie is_nav6up)
{ document.getElementById("toolTipLayer").innerHTML = content; toolTipSTYLE.display='block'; }
}
}

////Above java script is to Set Icon in Mouse Pointer by Javascript
//add this code into your page

// add this to your Webpage.
onmouseout="hide();" onmouseover="initToolTips();doImage('image name or text');show();

Detect Browser in Javascript

//browser detection

var agt=navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

Thursday, April 16, 2009

Signing a jar file using jarsigner

keytool -genkey -dname "cn=Mark Jones, ou=JavaSoft, o=Sun, c=US" -alias business -keypass kpi135 -keystore C:\working\mykeystore -storepass ab987c -validity 180



jarsigner -keystore C:\working\mykeystore -storepass ab987c -keypass kpi135 -sigfile SIG -signedjar sbundle.jar Notepad.jar business


jarsigner -verify sbundle.jar

Monday, April 13, 2009

JNLP Index Page

<html>
<body>
<a href="Notepad.jnlp">Launch Notepad Application</a>
</body>
</html>

JNLP File Structure

//Notepad.jnlp

<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for Notepad -->

<jnlp spec="1.0+"
codebase="http://website:port/projectname/"
href="Notepad.jnlp">
<information>
<title>Notepad kamal</title>
<vendor>kamal</vendor>
<description>Notepad Demo</description>
<homepage href="http://website:port/projectname/index.html"/>
<description kind="short">ClickMeApp uses 3 custom classes plus several
standard ones</description>
<offline-allowed/>
</information>
<resources>
<jar href="Notepad.jar"/>
<j2se version="1.6+"
href="http://java.sun.com/products/autodl/j2se"/>
</resources>
<application-desc main-class="Notepad"/>
</jnlp>

Thursday, March 12, 2009

game apps3

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package gameapps;

import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
*
* @author gdwebj6
*/
public class Main
{

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here

JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
System.out.println(ex);
}
MainFrame mf=new MainFrame();
// try{
// mf.setUndecorated(true);
// }catch(Exception e){System.out.println(e);}
mf.setVisible(true);
}

}

Game Apps2

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* MainFrame.java
*
* Created on Mar 6, 2009, 3:14:48 PM
*/

package gameapps;

import java.awt.event.KeyEvent;
import java.util.Random;
import java.util.Vector;
import javax.swing.JTextField;
import java.awt.*;


/**
*
* @author gdwebj6
*/
public class MainFrame extends javax.swing.JFrame {

/** Creates new form MainFrame */
public MainFrame()
{
// super("Game Window");
initComponents();
Dimension dm=Toolkit.getDefaultToolkit().getScreenSize();
setSize(240,280);
int height=dm.height;
int width=dm.width;
this.setLocation((width/2)-(240/2), (height/2)-(280/2));
tp=new TestProg();

}

private void close() {
System.exit(0);
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
pan1 = new javax.swing.JPanel();
txt1 = new javax.swing.JTextField();
txt2 = new javax.swing.JTextField();
txt3 = new javax.swing.JTextField();
pan2 = new javax.swing.JPanel();
txt6 = new javax.swing.JTextField();
txt5 = new javax.swing.JTextField();
txt4 = new javax.swing.JTextField();
pan3 = new javax.swing.JPanel();
txt9 = new javax.swing.JTextField();
txt8 = new javax.swing.JTextField();
txt7 = new javax.swing.JTextField();
pan_leb2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
pan_leb1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
pan_res1 = new javax.swing.JPanel();
res3 = new javax.swing.JTextField();
res2 = new javax.swing.JTextField();
res1 = new javax.swing.JTextField();
pan_res2 = new javax.swing.JPanel();
res4 = new javax.swing.JTextField();
res5 = new javax.swing.JTextField();
res6 = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
btn_sol = new javax.swing.JButton();
btn_clr = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
setUndecorated(true);

txt1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt1FocusLost(evt);
}
});
txt1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txt1KeyPressed(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
txt1KeyTyped(evt);
}
});

txt2.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt2FocusLost(evt);
}
});
txt2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt2KeyTyped(evt);
}
});

txt3.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt3FocusLost(evt);
}
});
txt3.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt3KeyTyped(evt);
}
});

javax.swing.GroupLayout pan1Layout = new javax.swing.GroupLayout(pan1);
pan1.setLayout(pan1Layout);
pan1Layout.setHorizontalGroup(
pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan1Layout.createSequentialGroup()
.addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pan1Layout.setVerticalGroup(
pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pan1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
);

txt6.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt6FocusLost(evt);
}
});
txt6.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt6KeyTyped(evt);
}
});

txt5.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt5FocusLost(evt);
}
});
txt5.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt5KeyTyped(evt);
}
});

txt4.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt4FocusLost(evt);
}
});
txt4.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt4KeyTyped(evt);
}
});

javax.swing.GroupLayout pan2Layout = new javax.swing.GroupLayout(pan2);
pan2.setLayout(pan2Layout);
pan2Layout.setHorizontalGroup(
pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan2Layout.createSequentialGroup()
.addComponent(txt4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pan2Layout.setVerticalGroup(
pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt5, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
);

txt9.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt9FocusLost(evt);
}
});
txt9.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt9KeyTyped(evt);
}
});

txt8.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt8FocusLost(evt);
}
});
txt8.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt8KeyTyped(evt);
}
});

txt7.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txt7FocusLost(evt);
}
});
txt7.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
txt7KeyTyped(evt);
}
});

javax.swing.GroupLayout pan3Layout = new javax.swing.GroupLayout(pan3);
pan3.setLayout(pan3Layout);
pan3Layout.setHorizontalGroup(
pan3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan3Layout.createSequentialGroup()
.addComponent(txt7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt8, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt9, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pan3Layout.setVerticalGroup(
pan3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt7, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt8, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txt9, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
);

jLabel1.setText("=");

jLabel2.setText("=");

jLabel3.setText("=");

javax.swing.GroupLayout pan_leb2Layout = new javax.swing.GroupLayout(pan_leb2);
pan_leb2.setLayout(pan_leb2Layout);
pan_leb2Layout.setHorizontalGroup(
pan_leb2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_leb2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(38, 38, 38)
.addComponent(jLabel2)
.addGap(37, 37, 37)
.addComponent(jLabel3)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pan_leb2Layout.setVerticalGroup(
pan_leb2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_leb2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
);

jLabel4.setText("=");

jLabel5.setText("=");

jLabel6.setText("=");

javax.swing.GroupLayout pan_leb1Layout = new javax.swing.GroupLayout(pan_leb1);
pan_leb1.setLayout(pan_leb1Layout);
pan_leb1Layout.setHorizontalGroup(
pan_leb1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
);
pan_leb1Layout.setVerticalGroup(
pan_leb1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_leb1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(jLabel6)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

res3.setEditable(false);

res2.setEditable(false);

res1.setEditable(false);

javax.swing.GroupLayout pan_res1Layout = new javax.swing.GroupLayout(pan_res1);
pan_res1.setLayout(pan_res1Layout);
pan_res1Layout.setHorizontalGroup(
pan_res1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_res1Layout.createSequentialGroup()
.addGroup(pan_res1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(res1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(res2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(res3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pan_res1Layout.setVerticalGroup(
pan_res1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_res1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(res1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(res2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(res3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
);

res4.setEditable(false);

res5.setEditable(false);

res6.setEditable(false);

javax.swing.GroupLayout pan_res2Layout = new javax.swing.GroupLayout(pan_res2);
pan_res2.setLayout(pan_res2Layout);
pan_res2Layout.setHorizontalGroup(
pan_res2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_res2Layout.createSequentialGroup()
.addComponent(res4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(res5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(res6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(70, Short.MAX_VALUE))
);
pan_res2Layout.setVerticalGroup(
pan_res2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pan_res2Layout.createSequentialGroup()
.addGroup(pan_res2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(res4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(res5, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(res6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

btn_sol.setText("Solve!!");
btn_sol.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_solActionPerformed(evt);
}
});

btn_clr.setText("Clear");
btn_clr.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_clrActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(57, Short.MAX_VALUE)
.addComponent(btn_clr)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_sol)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn_sol)
.addComponent(btn_clr))
.addContainerGap())
);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pan_res2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(pan_leb2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pan2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pan1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pan3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan_leb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan_res1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pan_res1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pan_leb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(pan1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan_leb2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pan_res2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gameapps/close.PNG"))); // NOI18N
jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
jLabel7MouseReleased(evt);
}
});

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(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(209, Short.MAX_VALUE)
.addComponent(jLabel7))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel7))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void txt1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt1KeyPressed
// TODO add your handling code here:

}//GEN-LAST:event_txt1KeyPressed

private void txt1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt1KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt1);

int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}
}//GEN-LAST:event_txt1KeyTyped

private void txt2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt2KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt2);

int x;
int p=evt.getKeyChar();
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt2KeyTyped

private void txt3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt3KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt3);

int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt3KeyTyped

private void txt4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt4KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt4);


int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt4KeyTyped

private void txt5KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt5KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt5);

int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt5KeyTyped

private void txt6KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt6KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt6);

int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt6KeyTyped

private void txt7KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt7KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt7);

int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt7KeyTyped

private void txt8KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt8KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt8);


int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt9.getText().length()>0)
{
x=txt9.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt8KeyTyped

private void txt9KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt9KeyTyped
// TODO add your handling code here:
stopKeyEvent(evt,txt9);


int x;
int p=evt.getKeyChar();
if(txt2.getText().length()>0)
{
x=txt2.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt3.getText().length()>0)
{
x=txt3.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt4.getText().length()>0)
{
x=txt4.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt5.getText().length()>0)
{
x=txt5.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt6.getText().length()>0)
{
x=txt6.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt7.getText().length()>0)
{
x=txt7.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt8.getText().length()>0)
{
x=txt8.getText().charAt(0);
if(x==p)
evt.consume();
}
if(txt1.getText().length()>0)
{
x=txt1.getText().charAt(0);
if(x==p)
evt.consume();
}

}//GEN-LAST:event_txt9KeyTyped

private void txt1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt1FocusLost
// TODO add your handling code here
setTotal(txt1,txt2,txt3,res1);
setTotal(txt1,txt4,txt7,res4);
}//GEN-LAST:event_txt1FocusLost

private void txt2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt2FocusLost
// TODO add your handling code here:
setTotal(txt2,txt1,txt3,res1);
setTotal(txt2,txt5,txt8,res5);
}//GEN-LAST:event_txt2FocusLost

private void txt3FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt3FocusLost
// TODO add your handling code here:
setTotal(txt3,txt2,txt1,res1);
setTotal(txt3,txt6,txt9,res6);
}//GEN-LAST:event_txt3FocusLost

private void txt4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt4FocusLost
// TODO add your handling code here:
setTotal(txt4,txt5,txt6,res2);
setTotal(txt4,txt1,txt7,res4);
}//GEN-LAST:event_txt4FocusLost

private void txt5FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt5FocusLost
// TODO add your handling code here:
setTotal(txt5,txt4,txt6,res2);
setTotal(txt5,txt2,txt8,res5);
}//GEN-LAST:event_txt5FocusLost

private void txt6FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt6FocusLost
// TODO add your handling code here:
setTotal(txt6,txt4,txt5,res2);
setTotal(txt6,txt3,txt9,res6);
}//GEN-LAST:event_txt6FocusLost

private void txt7FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt7FocusLost
// TODO add your handling code here:
setTotal(txt7,txt8,txt9,res3);
setTotal(txt7,txt1,txt4,res4);
}//GEN-LAST:event_txt7FocusLost

private void txt8FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt8FocusLost
// TODO add your handling code here:
setTotal(txt8,txt9,txt7,res3);
setTotal(txt8,txt5,txt2,res5);
}//GEN-LAST:event_txt8FocusLost

private void txt9FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txt9FocusLost
// TODO add your handling code here:
setTotal(txt9,txt7,txt8,res3);
setTotal(txt9,txt3,txt6,res6);
}//GEN-LAST:event_txt9FocusLost

private void btn_solActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_solActionPerformed
// TODO add your handling code here:
Random rndm=new Random();
int a=rndm.nextInt(tp.getVector().size());
// System.out.println(tp.getVector().size()+" "+a);
Vector temp=(Vector) tp.getVector().get(a);

Vector _2d_1=(Vector) temp.get(0);
Vector _2d_2=(Vector) temp.get(1);
Vector _2d_3=(Vector) temp.get(2);

// int[][] temp=(int[][]) tp.getVector().get(a);

// try{
// for(int p=0;p<tp.getVector().size();p++)
// {
// Vector temp=(Vector) tp.getVector().get(p);
// System.out.println(temp+" temp: "+temp.size());
// for(int i=0;i<temp.size();i++)
// {
// Vector _2d=(Vector) temp.get(i);
// System.out.println(_2d+" _2d: "+_2d.size());
// for(int j=0;j<3;j++)
// {
// System.out.print (" "+_2d.get(j));
// }
// System.out.println ();
// }
// System.out.println ("---------------------");
// }
// }
// catch(Exception e)
// {
// System.out.println(e);
// }

txt1.setText(""+_2d_1.get(0));
txt2.setText(""+_2d_1.get(1));
txt3.setText(""+_2d_1.get(2));
txt4.setText(""+_2d_2.get(0));
txt5.setText(""+_2d_2.get(1));
txt6.setText(""+_2d_2.get(2));
txt7.setText(""+_2d_3.get(0));
txt8.setText(""+_2d_3.get(1));
txt9.setText(""+_2d_3.get(2));
res1.setText("15");
res2.setText("15");
res3.setText("15");
res4.setText("15");
res5.setText("15");
res6.setText("15");
}//GEN-LAST:event_btn_solActionPerformed

private void btn_clrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_clrActionPerformed
// TODO add your handling code here:

txt1.setText("");
txt2.setText("");
txt3.setText("");
txt4.setText("");
txt5.setText("");
txt6.setText("");
txt7.setText("");
txt8.setText("");
txt9.setText("");
res1.setText("");
res2.setText("");
res3.setText("");
res4.setText("");
res5.setText("");
res6.setText("");
}//GEN-LAST:event_btn_clrActionPerformed

private void jLabel7MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseReleased
// TODO add your handling code here:
close();
}//GEN-LAST:event_jLabel7MouseReleased

public void stopKeyEvent(KeyEvent evt,JTextField txt)
{
int p=evt.getKeyChar();
if(p>=49 && p<=57)
{
if(txt.getText().length()==0)
{

}
else
evt.consume();
}
else
evt.consume();
}

public void setTotal(JTextField txt1,JTextField txt2,JTextField txt3,JTextField res1)
{
int sum=0;
if(!txt1.getText().equals(""))
{
if(!txt2.getText().equals("") && !txt3.getText().equals(""))
{
sum=Integer.parseInt(txt1.getText())+Integer.parseInt(txt2.getText())+Integer.parseInt(txt3.getText());
res1.setText(""+sum);
}
else if(!txt2.getText().equals("") && txt3.getText().equals(""))
{
sum=Integer.parseInt(txt1.getText())+Integer.parseInt(txt2.getText());
res1.setText(""+sum);
}
else if(txt2.getText().equals("") && !txt3.getText().equals(""))
{
sum=Integer.parseInt(txt1.getText())+Integer.parseInt(txt3.getText());
res1.setText(""+sum);
}
else
res1.setText(""+txt1.getText());
}
}
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new MainFrame().setVisible(true);
// }
// });
// }

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btn_clr;
private javax.swing.JButton btn_sol;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel pan1;
private javax.swing.JPanel pan2;
private javax.swing.JPanel pan3;
private javax.swing.JPanel pan_leb1;
private javax.swing.JPanel pan_leb2;
private javax.swing.JPanel pan_res1;
private javax.swing.JPanel pan_res2;
private javax.swing.JTextField res1;
private javax.swing.JTextField res2;
private javax.swing.JTextField res3;
private javax.swing.JTextField res4;
private javax.swing.JTextField res5;
private javax.swing.JTextField res6;
private javax.swing.JTextField txt1;
private javax.swing.JTextField txt2;
private javax.swing.JTextField txt3;
private javax.swing.JTextField txt4;
private javax.swing.JTextField txt5;
private javax.swing.JTextField txt6;
private javax.swing.JTextField txt7;
private javax.swing.JTextField txt8;
private javax.swing.JTextField txt9;
// End of variables declaration//GEN-END:variables
int done[]=new int[9];
int count=0;
TestProg tp;
}

Game Apps

package gameapps;

/**
* @(#)TestProg.java
*
*
* @author
* @version 1.00 2009/3/6
*/

import java.util.*;

public class TestProg
{
int main_arr[][]=new int[3][3];
int con_arr[]=new int[9];
int combi_arr[][];
int counter=0;
Vector vec;

public TestProg()
{
// fillConArray();
// suffleConArray();
vec=new Vector();
fillMainArray();
}

public void printArray(int[][] main_arr)
{
counter++;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print (main_arr[i][j]+" ");
}
System.out.println ();
}
System.out.println ();
System.out.println (counter);
System.out.println ();
}

public void saveInVector(int[][] main_arr)
{
Vector _2d=new Vector();
for(int i=0;i<3;i++)
{
Vector _1d=new Vector();
for(int j=0;j<3;j++)
{
_1d.addElement(main_arr[i][j]);
}
_2d.addElement(_1d);
}

// System.out.println ();
vec.addElement(_2d);
// System.out.println ();System.out.println ();System.out.println ();
// for(int p=0;p<getVector().size();p++)
// {
// int[][] temp=(int[][]) getVector().get(p);
// for(int i=0;i<3;i++)
// {
// for(int j=0;j<3;j++)
// {
// System.out.print (temp[i][j]+" ");
// }
// System.out.println ();
// }
// System.out.println ("---------------------");
// }
}

public Vector getVector()
{
return vec;
}

public void mainWork()
{
int res[]=calculate();

int flag=0;
int count=0;
for (int i = 0; i<res.length; i++)
{
if(res[i]==15)
count++;
}

if(count==6)
flag=1;

if(flag==1)
{
// printArray(main_arr);
saveInVector(main_arr);
}

}

public int[] calculate()
{
int sum[]=new int[6];
for (int i = 0; i<3; i++)
{
sum[i]=horizontalSum(i);
}

for (int i = 0; i<3; i++)
{
sum[i+3]=verticalSum(i);
}

return sum;
}

public int horizontalSum(int row_num)
{
int sum=0;

for(int i=0;i<3;i++)
{
sum+=main_arr[row_num][i];
}

return sum;
}

public int verticalSum(int col_num)
{
int sum=0;

for(int i=0;i<3;i++)
{
sum+=main_arr[i][col_num];
}

return sum;
}

public int[][] fillMainArray()
{
int temp_arr[][]=getCombiConArray();
for(int i=0;i<temp_arr.length;i++)
{
int temp[]=new int[9];
for (int j = 0; j<9; j++)
{
temp[j]=temp_arr[i][j];
}

for(int j=0;j<temp.length;j++)
{
int k=j/3;
int l=j%3;
main_arr[k][l]=temp[j];
}

mainWork();
}

return main_arr;
}

public int[][] getCombiConArray()
{
int temp_arr[]=suffleConArray();
Set set=new TreeSet();
int x=0;

combi_arr=new int[getFactorial(9)][9];

for(int i=0;i<temp_arr.length;i++)
{
for(int j=0;j<temp_arr.length;j++)
{
if(i==j)
continue;
for (int k = 0; k<temp_arr.length; k++)
{
if(j==k || i==k)
continue;
for (int l = 0; l<temp_arr.length; l++)
{
if(i==l || j==l || k==l)
continue;
for (int m = 0; m<temp_arr.length; m++)
{
if(i==m || j==m || k==m || l==m)
continue;
for (int n = 0; n<temp_arr.length; n++)
{
if(i==n || j==n || k==n || l==n || m==n)
continue;
for(int o=0; o<temp_arr.length; o++)
{
if(i==o || j==o || k==o || l==o || m==o || n==o)
continue;

for (int p = 0; p<temp_arr.length; p++)
{
if(i==p || j==p || k==p || l==p || m==p || n==p || o==p)
continue;
for (int q = 0; q<temp_arr.length; q++)
{
if(i==q || j==q || k==q || l==q || m==q || n==q || o==q || p==q)
continue;
combi_arr[x][0]=temp_arr[i];
combi_arr[x][1]=temp_arr[j];
combi_arr[x][2]=temp_arr[k];
combi_arr[x][3]=temp_arr[l];
combi_arr[x][4]=temp_arr[m];
combi_arr[x][5]=temp_arr[n];
combi_arr[x][6]=temp_arr[o];
combi_arr[x][7]=temp_arr[p];
combi_arr[x][8]=temp_arr[q];
x++;
}
}
}
}
}
}
}
}
}

// System.out.println ("X= "+x);

return combi_arr;
}

public int[] suffleConArray()
{
Random rand = new Random();
int[] suf_arr = fillConArray();

int n = 7,temp=0;
for (int i=0;i<9;i++)
{
// Random integers that range from from 0 to n
int x = rand.nextInt(n+1);
temp = suf_arr[i];
suf_arr[i] = suf_arr[x];
suf_arr[x] = temp;
}

// for(int i=0;i<9;i++)
// {
// System.out.println(suf_arr[i]);
// }

return suf_arr;
}

public int[] fillConArray()
{
for(int i=1;i<=9;i++)
con_arr[i-1]=i;

return con_arr;
}

public int getFactorial(int num)
{
int fact=0;
if(num==1)
return 1;
else
{
fact=num*getFactorial(num-1);

return fact;
}
}

// public static void main (String[] args)
// {
// TestProg test=new TestProg();
//
///* for(int i=0;i<test.fillConArray().length;i++)
// System.out.print (test.fillConArray()[i]);
// System.out.println();
//
// System.out.println("Factorial: "+test.getFactorial(9));
//
// test.fillMainArray();*/
// }
}