Monday, May 7, 2012
How to use JTextArea in JAVA?
The JTextArea is a subclass under javax.swing, same as JOptionPane. It is a multi-line area that displays plain texts.
Code:
//import class na gagamitin, dahil me object kelangan din JOptionPane
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class JtextArea {
public static void main(String[] args){
//gumawa ng object(lalagyanNgInfo. Default na sukat(2,2)
JTextArea lalagyanNgInfo= new JTextArea(2,2);
//mga kelangan sa program
String unangString,
pangalawangString,
ilalagayNaInfo="";
int unangNumber,
pangalawangNumber,
sum,difference,product;
double quotient;
//string to integer convertion
unangString=JOptionPane.showInputDialog("unang number: ");
unangNumber=Integer.parseInt(unangString);
pangalawangString=JOptionPane.showInputDialog("pangalawang number: ");
pangalawangNumber=Integer.parseInt(pangalawangString);
//mga formula
sum=unangNumber+pangalawangNumber;
difference=unangNumber-pangalawangNumber;
product=unangNumber*pangalawangNumber;
quotient=unangNumber/pangalawangNumber;
//laman ng ilalagay na info sa object(lalagyanNgInfo)
ilalagayNaInfo+="sum\tdifference\tproduct\tquotient";
ilalagayNaInfo+="\n"+sum+"\t"+difference+"\t"+product+"\t"+quotient;
lalagyanNgInfo.setText(ilalagayNaInfo);
JOptionPane.showMessageDialog(null,lalagyanNgInfo,"Eto ang mga sagot!",JOptionPane.INFORMATION_MESSAGE);
}
}
OUTPUT: quotient is zero instead 0.xxxx because data type used in quotient is integer. We focused on JTextArea.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment