Ito na po ung request nyo na code..
Please share with other ComElec1 students..
Below are two java codes, the first one SampleOne.java don’t have a main method, but the method inside this class is being called on the second java file, how? You just need to instantiate the 1st file on the 2nd file. Thats it!
SampleOne.java
//SampleOne.java
public class SampleOne
{
public int sumOfTwoNumbers(int x,int y)
{
int sum = x+y;
return sum;
}
}
SampleOneMain.java
//SampleOneMain .java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SampleOneMain extends JFrame implements ActionListener
{
//declare all gui components
JButton compute,reset;
JTextField num1,num2;
SampleOne s = new SampleOne();
//constructor
public SampleOneMain()
{
super("Webinar ni sir joell");
setLayout(new GridLayout(2,2,5,5));// rows and cols
compute = new JButton("Compute Sum");
reset = new JButton("reset");
num1 = new JTextField(5);
num2 = new JTextField(5);
add(num1);
add(num2);
add(compute);
add(reset);
compute.addActionListener(this);
reset.addActionListener(this);
setSize(250,250);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==compute)
{
int temp1=0,temp2=0;
String msg="";
temp1=Integer.parseInt(num1.getText());
temp2=Integer.parseInt(num2.getText());
msg="Sum is :"+s.sumOfTwoNumbers(temp1,temp2);
//msg = String + int = ?
JOptionPane.showMessageDialog(null,msg);
//my mga tanong ba?
//hehehe..
}
}
public static void main(String args[])
{
new SampleOneMain().setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
Related posts:
- Java 4-ever I saw this video at mashable.com Since i am teaching...
- 1IT1 Code Request Sa lhat ng student ko ng Intro to Prog. ito...









sir kasama po sa exam to? jason alvero here B)
Sir bat may nlabas na error dun sa SampleOne s = new SampleOne ();