You are on page 1of 24

http://www.planetsourcecode.com/vb/scripts/BrowseCategoryOrSearchResults.asp?

lng
WId=1&grpCategories=&txtMaxNumberOfEntriesPerPage=10&optSort=Alphabetical&chkTho
roughSearch=&blnTopCode=False&blnNewestCode=False&blnAuthorSearch=False&lngAutho
rId=&strAuthorName=&blnResetAllVariables=&blnEditCode=False&mblnIsSuperAdminAcce
ssOn=False&intFirstRecordOnPage=1&intLastRecordOnPage=10&intMaxNumberOfEntriesPe
rPage=10&intLastRecordInRecordset=50&chkCodeTypeZip=&chkCodeDifficulty=&chkCodeT
ypeText=&chkCodeTypeArticle=&chkCode3rdPartyReview=&txtCriteria=traffic&cmdGoToP
age=5&lngMaxNumberOfEntriesPerPage=10
http://www.sourcecodester.com/java?page=8
/**
* @(#)Stack.java
*
*
* @author :Abhilash Joseph C
* @version 1.00 2009/8/31
*/
import java.io.DataInputStream;
class MyStack
{
int Top=-1;
public static int MAX=2;
int Item[]=new int[MAX];
void Push(int X)
{
if(Top==MAX-1)
System.out.println("Stack is full !");
else{
Top++;
Item[Top]=X;
}
}
int Pop()
{
if(Top==-1)
return -1;
else{
return (Item[Top--]);
}
}
void Display()
{
if(Top==-1)
System.out.println("Stsck is Empty");
else{
for (int i=0;i<=Top;i++)
System.out.print("\t"+Item[i]);
}
System.out.println("");
}
}
class Stack
{

public static void main (String[] args) {


MyStack obj =new MyStack();
int opt=1;
int Num;
while(opt !=4)
{
System.out.println("========MENU==========");
System.out.println(" |1----->Push() |");
System.out.println(" |2----->Pop()
|");
System.out.println(" |3----->Display()|");
System.out.println(" |4----->Exit()
|");
System.out.println("======================");
System.out.println("Enter the option
:");
try{
DataInputStream in = new DataInputStream(System.
in);
opt=Integer.parseInt(in.readLine());
switch(opt)
{
case 1:
System.out.println("Enter the no
:");
Num=Integer.parseInt(in.readLine
());
obj.Push(Num);
break;
case 2:
Num=obj.Pop();
if(Num==-1)
System.out.println("Stac
k is Empty !") ;
else
System.out.println("The
poped item is :"+Num);
break;
case 3:
obj.Display();
break;
case 4:
break;
default :
System.out.println("In valued In
put !");
}
}
catch(Exception e){}
}
}
}

/**
* Write a description of class HigherLower here.
*
* @author (Vilchor G. Perdido)
* @version (September 11, 2010)
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.util.*;
public class HigherLower extends JApplet implements ActionListener
{
JTextField cardMain,card1,card2,card3;
JTextField score1,score2;
JButton btnNewGame,btnLower,btnHigher,btnStartGame;
int main,c1,c2,c3;

String card[] = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};


String hint,first,second,third;
int TRIES = 1,chances = 3,score = 0;;
int R, G, B;
final int MAX_SCORE = 3;
public void init()
{
JOptionPane.showMessageDialog(null,"Welcome to the Lower or Higher Java
Applet Game.\n\nEnjoy the Game!");
setLayout(null);
setSize(1024,460);
int R = (int) (250 * Math.random());
int G = (int) (250 * Math.random());
int B = (int) (250 * Math.random());
Color color = new Color(R,G,B);
cardMain = new JTextField(20);
cardMain.setBounds(10,30,250,270);
cardMain.setFont(new Font("Arial",Font.BOLD,220));
cardMain.setEditable(false);
cardMain.setBackground(Color.lightGray);
cardMain.setForeground(color);
cardMain.setBorder(BorderFactory.createEtchedBorder());
add(cardMain);
card1 = new JTextField(20);
card1.setBounds(260,30,250,270);
card1.setFont(new Font("Arial",Font.BOLD,220));
card1.setEditable(false);
card1.setVisible(false);
card1.setBackground(Color.lightGray);
card1.setForeground(color);
card1.setBorder(BorderFactory.createEtchedBorder());
add(card1);
card2 = new JTextField(20);
card2.setBounds(510,30,250,270);
card2.setFont(new Font("Arial",Font.BOLD,220));
card2.setEditable(false);
card2.setVisible(false);
card2.setBackground(Color.lightGray);
card2.setForeground(color);
card2.setBorder(BorderFactory.createEtchedBorder());
add(card2);
card3 = new JTextField(20);
card3.setBounds(760,30,240,270);
card3.setFont(new Font("Arial",Font.BOLD,220));
card3.setEditable(false);
card3.setVisible(false);
card3.setBackground(Color.lightGray);
card3.setForeground(color);
card3.setBorder(BorderFactory.createEtchedBorder());
add(card3);
btnStartGame = new JButton("Start Game");
btnStartGame.setBounds(150,320,250,60);

btnStartGame.setFont(new Font("Serif",Font.BOLD,32));
btnStartGame.setForeground(Color.green);
add(btnStartGame);
btnNewGame = new JButton("New Game");
btnNewGame.setBounds(150,320,250,60);
btnNewGame.setFont(new Font("Serif",Font.BOLD,32));
btnNewGame.setForeground(Color.green);
btnNewGame.setVisible(false);
add(btnNewGame);
btnHigher = new JButton("Higher");
btnHigher.setBounds(450,320,180,60);
btnHigher.setFont(new Font("CenturyGothic",Font.BOLD,32));
btnHigher.setForeground(Color.blue);
btnHigher.setEnabled(false);
add(btnHigher);
btnLower = new JButton("Lower");
btnLower.setBounds(650,320,180,60);
btnLower.setFont(new Font("CenturyGothic",Font.BOLD,32));
btnLower.setForeground(Color.red);
btnLower.setEnabled(false);
add(btnLower);
score1 = new JTextField("Your Score: " + score);
score1.setBounds(240,400,500,50);
score1.setFont(new Font("CenturyGothic",Font.BOLD,32));
score1.setBackground(Color.black);
score1.setForeground(Color.yellow);
score1.setEditable(false);
score1.setBorder(BorderFactory.createEtchedBorder());
add(score1);
btnNewGame.requestFocus();
btnStartGame.addActionListener(this);
btnNewGame.addActionListener(this);
btnHigher.addActionListener(this);
btnLower.addActionListener(this);
}
public void paint(Graphics g)
{
showStatus("Author: Vilchor G. Perdido");
}
public void gameStart()
{
main = (int) (12 * Math.random());
c1 = (int) (12 * Math.random());
c2 = (int) (12 * Math.random());
c3 = (int) (12 * Math.random());
hint= card[main];
first = card[c1];
second = card[c2];
third = card[c3];
cardMain.setText(""+hint);
}
public void displayStat()
{

if(TRIES<3)
{
//JOptionPane.showMessageDialog(null,"You still have " + --chances +
" tries.");
++TRIES;
}
else
{
//JOptionPane.showMessageDialog(null,"Sorry, No More TRIES!");
btnHigher.setEnabled(false);
btnLower.setEnabled(false);
btnNewGame.setEnabled(true);
btnNewGame.requestFocus();
if(score==3)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ". \nEXCELLENT!You are a GENIUS!.");
}
else if(score==2)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nVERY GOOD! You are SMART.");
}
else if(score==1)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nGOOD! You are NORMAL.");
}
else
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nBETTER LUCK NEXT TIME!!!\nYou are an IDIOT!");
}
//JOptionPane.showConfirmDialog(null,"Try another game?","EXIT", JOp
tionPane.YES_NO_OPTION);
continueGame();
}
}
public void guessHigher()
{
if (TRIES==1)
{
btnNewGame.setEnabled(false);
if(c1>main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c1==main)
{
card1.setVisible(true);
card1.setText(""+first);

JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");


}
else
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else if (TRIES==2)
{
btnNewGame.setEnabled(false);
if(c2>c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c2==c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else
{
btnNewGame.setEnabled(false);
if(c3>c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You win!\nSorry, No More TRI
ES!");
score++;
score1.setText("Your Score: " + score);
}
else if(c3==c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"Draw!\nSorry, No More TRIES!
");
}

else
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You lose!\nSorry, No More TR
IES!");
}
}
}
public void guessLower()
{
if(TRIES==1)
{
btnNewGame.setEnabled(false);
if(c1<main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c1==main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else if (TRIES==2)
{
btnNewGame.setEnabled(false);
if(c2<c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c2==c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{

card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else
{
btnNewGame.setEnabled(false);
if(c3<c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You win!\nSorry, No More TRI
ES!");
score++;
score1.setText("Your Score: " + score);
}
else if(c3==c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"Draw!\nSorry, No More TRIES!
");
}
else
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You lose!\nSorry, No More TR
IES!");
}
}
}
public void randomColor()
{
R = (int) (250 * Math.random());
G = (int) (250 * Math.random());
B = (int) (250 * Math.random());
cardMain.setForeground(new Color(R,G,B));
card1.setForeground(new Color(R,G,B));
card2.setForeground(new Color(R,G,B));
card3.setForeground(new Color(R,G,B));
}
public void newGame()
{
TRIES = 1;
chances = 3;
score = 0;
score1.setText("Your Score: " + score);
card1.setText("");
card2.setText("");
card3.setText("");
main = (int) (12 * Math.random());
c1 = (int) (12 * Math.random());

c2 = (int) (12 * Math.random());


c3 = (int) (12 * Math.random());
hint = card[main];
first = card[c1];
second = card[c2];
third = card[c3];
cardMain.setText(""+hint);
btnHigher.setEnabled(true);
btnLower.setEnabled(true);
}
public void invisible()
{
card1.setVisible(false);
card2.setVisible(false);
card3.setVisible(false);
}
public void startGame()
{
btnStartGame.setVisible(false);
btnNewGame.setVisible(true);
btnNewGame.setEnabled(false);
btnHigher.setEnabled(true);
btnLower.setEnabled(true);
}
public void stopGame()
{
btnStartGame.setVisible(false);
btnNewGame.setVisible(false);
btnHigher.setVisible(false);
btnLower.setVisible(false);
score1.setVisible(false);
cardMain.setVisible(false);
card1.setVisible(false);
card2.setVisible(false);
card3.setVisible(false);
}
public void continueGame()
{
int n = JOptionPane.showConfirmDialog(null,"Would you like to continue?"
,"Lower or Higher",JOptionPane.YES_NO_OPTION);
if(n==0)
{
startGame();
btnNewGame.setEnabled(true);
btnHigher.setEnabled(false);
btnLower.setEnabled(false);
}
else
{
stopGame();
}

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnStartGame)
{
gameStart();
startGame();
}
if(e.getSource()==btnHigher)
{
guessHigher();
displayStat();
}
if(e.getSource()==btnLower)
{
guessLower();
displayStat();
}
if(e.getSource()==btnNewGame)
{
newGame();
randomColor();
invisible();
}
}
}

import
import
import
import
import

java.beans.PropertyChangeEvent;
java.beans.PropertyChangeListener;
java.util.Random;
javax.swing.JOptionPane;
javax.swing.SwingWorker;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ProgressBarDemo.java
*
* Created on Jul 10, 2010, 11:35:31 PM
*/
/**
*
* @author Wilson Leong
*/
public class ProgressBarDemo extends javax.swing.JFrame {
class Task extends SwingWorker<Void,Void>{
public Void doInBackground(){
int progress = 0;
Random random = new Random();
setProgress(0);
jtaList.setText("");
while(progress < 100){
try{
Thread.sleep(random.nextInt(1000));
}
catch(InterruptedException ex){
}
progress += (Integer)random.nextInt(10);
setProgress(Math.min(progress,100));
jtaList.append(String.format("%d%% complete.", progress) + "\n")
;
}
JOptionPane.showMessageDialog(null, "The loading is complete.", "Com
plete", JOptionPane.INFORMATION_MESSAGE);
jbtOk.setEnabled(true);
return null;
}
}
/** Creates new form ProgressBarDemo */
public ProgressBarDemo() {
initComponents();

}
/** 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:i
nitComponents
private void initComponents() {
jpbProgressBar = new javax.swing.JProgressBar();
jbtOk = new java.awt.Button();
jScrollPane1 = new javax.swing.JScrollPane();
jtaList = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("JProgressBarDemo");
jbtOk.setLabel("Ok");
jbtOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtOkActionPerformed(evt);
}
});
jtaList.setColumns(20);
jtaList.setEditable(false);
jtaList.setRows(5);
jScrollPane1.setViewportView(jtaList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(82, 82, 82)
.addComponent(jbtOk, javax.swing.GroupLayout.PREFERRED_S
IZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jpbProgressBar, javax.swing.GroupLayout.PR
EFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFA
ULT_SIZE, 207, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createS
equentialGroup()

.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SI
ZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jpbProgressBar, javax.swing.GroupLayout.PREFERRED_
SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jbtOk, javax.swing.GroupLayout.PREFERRED_SIZE, jav
ax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jbtOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
ST:event_jbtOkActionPerformed
jpbProgressBar.setStringPainted(true);
task = new Task();
task.addPropertyChangeListener(new PropertyChangeListener(){
public void propertyChange(PropertyChangeEvent e){
if("progress".equals(e.getPropertyName())){
jbtOk.setEnabled(false);
int progress = (Integer)e.getNewValue();
jpbProgressBar.setValue(progress);
}
}
});
task.execute();
}//GEN-LAST:event_jbtOkActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ProgressBarDemo().setVisible(true);
}
});
}
private Task task;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private java.awt.Button jbtOk;
private javax.swing.JProgressBar jpbProgressBar;
private javax.swing.JTextArea jtaList;
// End of variables declaration//GEN-END:variables
}

/**
* Write a description of class HigherLower here.
*
* @author (Vilchor G. Perdido)
* @version (September 11, 2010)
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import java.util.*;
public class HigherLower extends JApplet implements ActionListener
{
JTextField cardMain,card1,card2,card3;
JTextField score1,score2;
JButton btnNewGame,btnLower,btnHigher,btnStartGame;
int main,c1,c2,c3;
String card[] = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
String hint,first,second,third;
int TRIES = 1,chances = 3,score = 0;;
int R, G, B;
final int MAX_SCORE = 3;

public void init()


{
JOptionPane.showMessageDialog(null,"Welcome to the Lower or Higher Java
Applet Game.\n\nEnjoy the Game!");
setLayout(null);
setSize(1024,460);
int R = (int) (250 * Math.random());
int G = (int) (250 * Math.random());
int B = (int) (250 * Math.random());
Color color = new Color(R,G,B);
cardMain = new JTextField(20);
cardMain.setBounds(10,30,250,270);
cardMain.setFont(new Font("Arial",Font.BOLD,220));
cardMain.setEditable(false);
cardMain.setBackground(Color.lightGray);
cardMain.setForeground(color);
cardMain.setBorder(BorderFactory.createEtchedBorder());
add(cardMain);
card1 = new JTextField(20);
card1.setBounds(260,30,250,270);
card1.setFont(new Font("Arial",Font.BOLD,220));
card1.setEditable(false);
card1.setVisible(false);
card1.setBackground(Color.lightGray);
card1.setForeground(color);
card1.setBorder(BorderFactory.createEtchedBorder());
add(card1);
card2 = new JTextField(20);
card2.setBounds(510,30,250,270);
card2.setFont(new Font("Arial",Font.BOLD,220));
card2.setEditable(false);
card2.setVisible(false);
card2.setBackground(Color.lightGray);
card2.setForeground(color);
card2.setBorder(BorderFactory.createEtchedBorder());
add(card2);
card3 = new JTextField(20);
card3.setBounds(760,30,240,270);
card3.setFont(new Font("Arial",Font.BOLD,220));
card3.setEditable(false);
card3.setVisible(false);
card3.setBackground(Color.lightGray);
card3.setForeground(color);
card3.setBorder(BorderFactory.createEtchedBorder());
add(card3);
btnStartGame = new JButton("Start Game");
btnStartGame.setBounds(150,320,250,60);
btnStartGame.setFont(new Font("Serif",Font.BOLD,32));
btnStartGame.setForeground(Color.green);
add(btnStartGame);
btnNewGame = new JButton("New Game");
btnNewGame.setBounds(150,320,250,60);

btnNewGame.setFont(new Font("Serif",Font.BOLD,32));
btnNewGame.setForeground(Color.green);
btnNewGame.setVisible(false);
add(btnNewGame);
btnHigher = new JButton("Higher");
btnHigher.setBounds(450,320,180,60);
btnHigher.setFont(new Font("CenturyGothic",Font.BOLD,32));
btnHigher.setForeground(Color.blue);
btnHigher.setEnabled(false);
add(btnHigher);
btnLower = new JButton("Lower");
btnLower.setBounds(650,320,180,60);
btnLower.setFont(new Font("CenturyGothic",Font.BOLD,32));
btnLower.setForeground(Color.red);
btnLower.setEnabled(false);
add(btnLower);
score1 = new JTextField("Your Score: " + score);
score1.setBounds(240,400,500,50);
score1.setFont(new Font("CenturyGothic",Font.BOLD,32));
score1.setBackground(Color.black);
score1.setForeground(Color.yellow);
score1.setEditable(false);
score1.setBorder(BorderFactory.createEtchedBorder());
add(score1);
btnNewGame.requestFocus();
btnStartGame.addActionListener(this);
btnNewGame.addActionListener(this);
btnHigher.addActionListener(this);
btnLower.addActionListener(this);
}
public void paint(Graphics g)
{
showStatus("Author: Vilchor G. Perdido");
}
public void gameStart()
{
main = (int) (12 * Math.random());
c1 = (int) (12 * Math.random());
c2 = (int) (12 * Math.random());
c3 = (int) (12 * Math.random());
hint= card[main];
first = card[c1];
second = card[c2];
third = card[c3];
cardMain.setText(""+hint);
}
public void displayStat()
{
if(TRIES<3)
{
//JOptionPane.showMessageDialog(null,"You still have " + --chances +
" tries.");
++TRIES;

}
else
{
//JOptionPane.showMessageDialog(null,"Sorry, No More TRIES!");
btnHigher.setEnabled(false);
btnLower.setEnabled(false);
btnNewGame.setEnabled(true);
btnNewGame.requestFocus();
if(score==3)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ". \nEXCELLENT!You are a GENIUS!.");
}
else if(score==2)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nVERY GOOD! You are SMART.");
}
else if(score==1)
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nGOOD! You are NORMAL.");
}
else
{
JOptionPane.showMessageDialog(null,"YOU GOT " + score + " out of
" + MAX_SCORE + ".\nBETTER LUCK NEXT TIME!!!\nYou are an IDIOT!");
}
//JOptionPane.showConfirmDialog(null,"Try another game?","EXIT", JOp
tionPane.YES_NO_OPTION);
continueGame();
}
}
public void guessHigher()
{
if (TRIES==1)
{
btnNewGame.setEnabled(false);
if(c1>main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c1==main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{

card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else if (TRIES==2)
{
btnNewGame.setEnabled(false);
if(c2>c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c2==c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else
{
btnNewGame.setEnabled(false);
if(c3>c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You win!\nSorry, No More TRI
ES!");
score++;
score1.setText("Your Score: " + score);
}
else if(c3==c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"Draw!\nSorry, No More TRIES!
");
}
else
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You lose!\nSorry, No More TR

IES!");
}
}
}
public void guessLower()
{
if(TRIES==1)
{
btnNewGame.setEnabled(false);
if(c1<main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c1==main)
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{
card1.setVisible(true);
card1.setText(""+first);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}
}
else if (TRIES==2)
{
btnNewGame.setEnabled(false);
if(c2<c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You win!\nYou still have " +
--chances + " tries.");
score++;
score1.setText("Your Score: " + score);
}
else if(c2==c1)
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"Draw!\nYou still have " + -chances + " tries.");
}
else
{
card2.setVisible(true);
card2.setText(""+second);
JOptionPane.showMessageDialog(null,"You lose!\nYou still have "
+ --chances + " tries.");
}

}
else
{
btnNewGame.setEnabled(false);
if(c3<c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You win!\nSorry, No More TRI
ES!");
score++;
score1.setText("Your Score: " + score);
}
else if(c3==c2)
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"Draw!\nSorry, No More TRIES!
");
}
else
{
card3.setVisible(true);
card3.setText(""+third);
JOptionPane.showMessageDialog(null,"You lose!\nSorry, No More TR
IES!");
}
}
}
public void randomColor()
{
R = (int) (250 * Math.random());
G = (int) (250 * Math.random());
B = (int) (250 * Math.random());
cardMain.setForeground(new Color(R,G,B));
card1.setForeground(new Color(R,G,B));
card2.setForeground(new Color(R,G,B));
card3.setForeground(new Color(R,G,B));
}
public void newGame()
{
TRIES = 1;
chances = 3;
score = 0;
score1.setText("Your Score: " + score);
card1.setText("");
card2.setText("");
card3.setText("");
main
c1 =
c2 =
c3 =

= (int) (12
(int) (12 *
(int) (12 *
(int) (12 *

* Math.random());
Math.random());
Math.random());
Math.random());

hint = card[main];
first = card[c1];

second = card[c2];
third = card[c3];
cardMain.setText(""+hint);
btnHigher.setEnabled(true);
btnLower.setEnabled(true);
}
public void invisible()
{
card1.setVisible(false);
card2.setVisible(false);
card3.setVisible(false);
}
public void startGame()
{
btnStartGame.setVisible(false);
btnNewGame.setVisible(true);
btnNewGame.setEnabled(false);
btnHigher.setEnabled(true);
btnLower.setEnabled(true);
}
public void stopGame()
{
btnStartGame.setVisible(false);
btnNewGame.setVisible(false);
btnHigher.setVisible(false);
btnLower.setVisible(false);
score1.setVisible(false);
cardMain.setVisible(false);
card1.setVisible(false);
card2.setVisible(false);
card3.setVisible(false);
}
public void continueGame()
{
int n = JOptionPane.showConfirmDialog(null,"Would you like to continue?"
,"Lower or Higher",JOptionPane.YES_NO_OPTION);
if(n==0)
{
startGame();
btnNewGame.setEnabled(true);
btnHigher.setEnabled(false);
btnLower.setEnabled(false);
}
else
{
stopGame();
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnStartGame)

{
gameStart();
startGame();
}
if(e.getSource()==btnHigher)
{
guessHigher();
displayStat();
}
if(e.getSource()==btnLower)
{
guessLower();
displayStat();
}
if(e.getSource()==btnNewGame)
{
newGame();
randomColor();
invisible();
}
}
}

Imports System.Data.SqlClient
Public Class Form1
Private Sub search_Click(sender As Object, e As EventArgs) Handles search.Cl
ick
Dim connectionstring As String = "Data source=PC\MSSQLSERVER2014;Initial
Catalog=database;User Id=sa;Password=123456"
Dim sql As String = "Select OPERATION,QTY,BARCODE,STYLE,PONUM,ISSUENO fr
om PT_COUPON where ISSUENO='" & issn.Text & "' and OPERATION='" & po1.Text & "'
and QTY='" & qty1.Text & "'"
Dim connection As New SqlConnection(connectionstring)
Dim dataadapter As New SqlDataAdapter(sql, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "PT_COUPON")
connection.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "PT_COUPON"
End Sub

You might also like