Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

All about programming (Specially c, c++, VB, Java)

Patulong naman po sa Java program ko. btnMin not functioning well. When I try to click btnFill then btnMin it works perfectly fine, but when I try to click btnFill, btnSort, btnMax and btnMin consecutively btnMin not working. Please help me.

Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;  

public class array extends Applet implements ActionListener
{
    Button btnFill = new Button("Fill Array");
    Button btnSort = new Button("Sort");
    Button btnMax = new Button("Find Maximum");
    Button btnMin = new Button("Find Minimum");
    TextArea Display = new TextArea(10,20);
    Label lblMaxMin = new Label("##################");
    int[] myArray = new int[5];
    int x;
    String strOutput = "";

public void init()
{
    Panel pnl1 = new Panel();
    Panel pnl2 = new Panel();
    Panel pnl3 = new Panel();

    pnl1.setLayout(new GridLayout(4,0));
    pnl1.add(btnFill);    btnFill.addActionListener(this);
    pnl1.add(btnSort);    btnSort.addActionListener(this);
    pnl1.add(btnMax);    btnMax.addActionListener(this);
    pnl1.add(btnMin);    btnMin.addActionListener(this);

    pnl2.setLayout(new GridLayout(1,1));
    pnl2.add(Display);

    pnl3.setLayout(new GridLayout(6,0));
    pnl3.add(lblMaxMin);
    add(pnl1);
    add(pnl2);
    add(pnl3);
}

public void actionPerformed(ActionEvent a)
{
    Object Obj = a.getSource();

    if(Obj == btnFill)
    {
      Display.setText("");
      for(int x=0; x<myArray.length; x++)
      {
        myArray[x] = (int)(Math.random()*100)+1;
        Display.append("[" + (x+1) + "]" + "   " + myArray[x] + "\n");
      }
    }

    else if(Obj == btnSort)
    {
      Display.setText("");
      Arrays.sort(myArray);
      for(int x=0; x<myArray.length; x++)
      {
        Display.append("[" + (x+1) + "]" + "   " + myArray[x] + "\n");
      }
    }

    else if(Obj == btnMax)
    {
      lblMaxMin.setText("");
      int max = myArray[0];
      for(int x=0; x<myArray.length; x++)
      {
        if(myArray[x] > max)
        {
        max = myArray[x];
        lblMaxMin.setText("Maximum Number =" + max);
        }
      }
    }

    else
    {
      lblMaxMin.setText("");
      int min = myArray[0];
      for(int x=0; x<myArray.length; x++)
      {
        if(myArray[x] < min)
        {
        min = myArray[x];
        lblMaxMin.setText("Minimum Number =" + min);
        }
      }
    }
}
}

may error message ba or unexpected lang ang output? honestly wala pa (sa ngayon) akong nakikitang mali sa code mo.
 
PLEASE HELP! Nagtatanong lang po.

I have 2 identical USB Numeric Keypads (lets say, Keypads A and B) connected to the same computer. I want to create a windows application that can
remap the keys from each keypad to a single string so that whatever key from keypad A is pressed will return A and B from keypad B

Tanong:

Ano po ang pinaka dabest na gamitin dito? C? C++? o Java?
 
Last edited:
while [download process is running whether it be wget or firefox] <----- what must this code look?
do
some codes
done
 
Last edited:
[/CODE]
post mo dito nagawa mo na, tignan natin kung pano natin dadagdagan.
Code:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<dos.h>

main() {
	int m[10][10];
  	clrscr();

	//draw the grid (max of 10 rows)
	int row = 10; //grid height
	int col = 10; //grid width
	int r, c, w=4, h=2;
	int top = (24-row*h)/2;
	int left= (80-col*w)/2;
	char ch, ESC=27;
	textbackground(WHITE);
	clrscr();

	do {
		ch=' ';
		for (r=1; r<=row; r++) {
			for (c=1; c<=col; c++) {
				//textbackground(CYAN);
				textcolor(RED);
				gotoxy(w*c-3+left+17,h*r-1+top); cprintf(" --- ");
				gotoxy(w*c-3+left+17,h*r+0+top); cprintf("|   |");
				gotoxy(w*c-3+left+17,h*r+1+top); cprintf(" --- ");
			}
		}

		//initialize matrix to 0
		for (r=1; r<=5; r++)
			for (c=1;c<=5; c++) {
				m[r-1][c-1]=0;
				gotoxy(w*c-1+left,h*r+0+top);
				textcolor(YELLOW);
			}
		gotoxy(10,row+left-h);
		textcolor(GREEN); cout<<endl;
		cprintf("Instructions:"); cout<<endl;
		cprintf("You are the first move (X)"); cout<<endl;
		cprintf("You must complete 5(X) either,"); cout<<endl;
		cprintf(" diagonal,horizontal, or vertical"); cout<<endl;
		cprintf("You will play against the computer"); cout<<endl;

		gotoxy(25, h*row+3+top);
		//textbackground(WHITE);
		textcolor(GREEN);
		cprintf("[ESC] Exit [ENTER] Select [R] Restart");

		//walk the grid using arrow keys
		char winner= ' ';
		int j, k,  sum;
		r=2, c=2; gotoxy(w*c-1+left+13,h*r+top);

		do {
			if (kbhit()) {
				ch=getch();
				switch (ch) {
					case 72: if (r>  1) r--; break; //up
					case 80: if (r<row) r++; break; //dn
					case 75: if (c>  1) c--; break; //left
					case 77: if (c<col) c++; break; //right
				}

				gotoxy(w*c-1+left+17,h*r+0+top);

				if (ch=='X' || ch=='O' ||ch=='x' || ch=='o') {
				  //	textbackground(CYAN);
					textcolor(YELLOW);
					cprintf("%c", ch);

					if (ch=='X' || ch=='x') m[r-1][c-1]=4;
					if (ch=='O' || ch=='o') m[r-1][c-1]=1;

				  //check for 5 marks in a row
					sum=0; for(j=0; j<3; j++) sum+=m[r-1][j];
					if (sum==12) winner='X'; if (sum==3) winner='O'; else
					//check for 5 marks in a col
					sum=0; for(j=0; j<3; j++) sum+=m[j][c-1];
					if (sum==12) winner='X'; if (sum==3) winner='O';
					//check for 5 marks in a \ diagonal
					sum=0; for(j=0; j<3; j++) sum+=m[j+5][j+5];
					if (sum==12) winner='X'; if (sum==3) winner='O';
					//check for 5 marks in a / diagonal
					sum=0; for(j=0; j<3; j++) sum+=m[j+5][2-j];
					if (sum==12) winner='X'; if (sum==3) winner='O';

					//check for a draw
					int ctr0=0;
					for (j=0; j<5; j++)
						for (k=0; k<5; k++)
							if (m[j][k]==0) ctr0++;
					if (ctr0==0) winner='D';

					//declare if somebody won
					if (winner=='X' || winner =='O') {
						textcolor(RED);
						//textbackground(WHITE);
						gotoxy(30, h*1-3+top);
						cprintf(" %c Wins! (Press ENTER)", winner);
						getch();
					}
					if (winner=='D') {
						textcolor(RED);
						//textbackground(WHITE);
						gotoxy(30,h*1-3+top);
						cprintf("  Draw! (Press ENTER)", winner);
						getch();
					}

				}

			} //if
		} while (ch!=ESC && ch!='R' && ch!='r' && winner==' ') ;
		clrscr();
	} while (ch!=ESC);

	return 0;
}

Yan po ung code na binigay ng prof namin.. imomodify lang po namin kung papaano sisingitan ng AI,, tska ung check po jan ng 5 in a row mali.. tnx po..
 
may error message ba or unexpected lang ang output? honestly wala pa (sa ngayon) akong nakikitang mali sa code mo.


wala pong error, pag ni-click ko yung buttons sunod-sunod meaning last yung btnMin hindi nya piniprint yung Minimum number, blank lang lumalabas, pero pag ni-click ko yung btnFill tapos btnMin nagpriprint naman yung Minimum number. Ano kaya dapat kong gawin?
 
wala pong error, pag ni-click ko yung buttons sunod-sunod meaning last yung btnMin hindi nya piniprint yung Minimum number, blank lang lumalabas, pero pag ni-click ko yung btnFill tapos btnMin nagpriprint naman yung Minimum number. Ano kaya dapat kong gawin?

kasi nagkakalaman lang ang array mo pag nagclick ka sa btnFill. wala kang makukuhang minimum kung walang laman ang array mo kaya kelangan mo talaga iclick ang btnfill before btnmin para may makuha kang min value. to solve that, lagyan mo na agad ng random values ang array mo sa umpisa pa lang, meaning yung codes mo dun sa btnfill, icopy mo dun sa constructor ng class mo
 
kasi nagkakalaman lang ang array mo pag nagclick ka sa btnFill. wala kang makukuhang minimum kung walang laman ang array mo kaya kelangan mo talaga iclick ang btnfill before btnmin para may makuha kang min value. to solve that, lagyan mo na agad ng random values ang array mo sa umpisa pa lang, meaning yung codes mo dun sa btnfill, icopy mo dun sa constructor ng class mo

hindi po yun ang problema ko. kapag po kasi sunod-sunod kong kiniclick yung mga button(btnFill, btnSort, btnMax at btnMin) yung btnMin lang ang walang piniprint blank lang yung label.
 
Gust0 ko rin matot0 ng java, VB lang kc tnu2r0 samin sa skul.
 
pa help nmn po about c programming, enge lng po me ng konting kaalaman kng pnu po gmwa ng ATM program.. tnx po!!
 
wala pong error, pag ni-click ko yung buttons sunod-sunod meaning last yung btnMin hindi nya piniprint yung Minimum number, blank lang lumalabas, pero pag ni-click ko yung btnFill tapos btnMin nagpriprint naman yung Minimum number. Ano kaya dapat kong gawin?

ilagay mo yung pagset mo ng text sa label ng min outside of the for loop. ang nangyayari kasi is pag yung unang element ang minimum mo, di ka makakapasok dun sa if(myArray[x]<min) kaya di naseset ang text kung ang first element ang minimum. nangyayari yun pagkasort mo kaya walang lumalabas kung sorted na ang array
 
@mahapulaa

the same thing also happens kung ang 1st element mo ang max, hindi sya maprint. solution uli is ilabas mo yung settext mo sa for loop. kung ayaw mo na may lumabas na value pag wala pang array na nagegenerate, gawa ka na lang ng isang boolean variable na magiging true pag napress na ang btnfill, then before ka magprint ng min and max, check mo kung true yung variable na yun
 
ilagay mo yung pagset mo ng text sa label ng min outside of the for loop. ang nangyayari kasi is pag yung unang element ang minimum mo, di ka makakapasok dun sa if(myArray[x]<min) kaya di naseset ang text kung ang first element ang minimum. nangyayari yun pagkasort mo kaya walang lumalabas kung sorted na ang array

:clap: ok na. Salamat sa tulong :yipee:
 
nEed Java pr0gram pr0ject pr0posal wid descripti0ns and s0urce c0des na dn p0. . .using Netbeans 6.7.1
ung simpLe lang p0 per0 aztig. .pang2ndyr c0llege. .bSIT.
First tym 2 hav a javA pr0gramming subject diz sEm eh. . .tnx p0. . Sna ma2lungan ni0 q mga Sir. . .:weep:
 
bago lang po ako sa visual c++, as in level 0, i needed lang po kasi to, native vb6 programmer po aq...
i need a source with this functionalities
a screen that have two input boxes
entries must be save (appended) to a text file
Loop lang po ng loop until terminated by user
Any one po pls na knowledge sa visual c++
 
help nmAn,!anu p0 maganda pRoject pr0posal nah mdali lng ic0de sa Java,. Using Netbeans 6.7.1. . Final pr0ject kz nmen yan,den ide2fense p p0. .tnx.
 
hi po thanks sa mga tips nyo uhm ngayon po simple question lng how can i create a box ung asteris or other design using turbo c sensya na naguumpisa pa lng po tlg ako :help:
 
hi po thanks sa mga tips nyo uhm ngayon po simple question lng how can i create a box ung asteris or other design using turbo c sensya na naguumpisa pa lng po tlg ako :help:

search mo about looping. madali lang yan.
 
search mo about looping. madali lang yan.

thanks sa tip sir medyo naguluhan lng ako kase may sinasabi pa ung prof ko na gotoxy nawala ko kase ung kopya ko minadali nya kase ung turo ung mga kaklase ko nmn wlang kopya. Using for loop dba sir can u give me a sample? thank you:salute:
 
thanks sa tip sir medyo naguluhan lng ako kase may sinasabi pa ung prof ko na gotoxy nawala ko kase ung kopya ko minadali nya kase ung turo ung mga kaklase ko nmn wlang kopya. Using for loop dba sir can u give me a sample? thank you:salute:

pwede rin yung gotoxy

for example, you want to print a 5x5 square using *


unahin mo muna ung pag print mo ng 5 * pahalang

Code:
for(i=0;i<5;i++){
printf("*");
}
what this code does is simple. it initialized to 0, and while i is less than 5, it will print single * on screen. when it reaches the closing }, it will increase i by 1.

dahil 5x5 ung square mo, kailangan mo ulitin ung code above 5 times in a new line. gawin muna natin ung 5 times na new line para simple.

Code:
for(x=0;x<5;x++){
printf("\n");
}
if you can see, pareho lang dun sa unang example, pinalitan ko lang ung "*" ng \n. now, pagsasamahin mo lang sila

Code:
for(i=0;i<5;i++){
         for(x=0;x<5;x++){
         printf("*");
         }
printf("\n");
}

simple lang di ba? onting tyaga lang mag-isip at logic yan bro.
 
Last edited:
Back
Top Bottom