- Messages
- 248
- Reaction score
- 0
- Points
- 26
<h1>Java Expert {I need Your Help};<h1>
Hi mga ka symb. gusto ko sanang magpatulong ma complete tong code na ito, self study kasi pero dito ako hindi ma kuha...
Code:
private void GramsActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000; //1kg = 1000 grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void MilliActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000000; //1kg = 1000000 milli grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
/ /paki complete po sa code yung hindi na mag error im using bluej compiler.
OUTPUT:
View attachment 254999
Thanks advance sa GUI na ako pero ang hirap ng action ng mga button. THank you.
- - - Updated - - -
Pa tulong na ayos ko dito pero sa pagconvert ako nahihirapan, ! please !
//Import packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//Main class
public class conve{
//Declare variables
private JButton plainJButton;
static JFrame frame1;
static Container pane;
static JButton btnGrams, btnMilligrams, btnExit;
static JLabel lblWeight, lblResult;
static JTextField txtWeight, txtResult;
static Insets insets;
public static void main (String args[]){
//Create the frame
frame1 = new JFrame ("Grams to Milligrams Converter");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize (320,300);
pane = frame1.getContentPane();
insets = pane.getInsets();
pane.setLayout (null);
//Create controls
btnGrams = new JButton ("Grams");
btnMilligrams = new JButton ("Milligrams");
btnExit = new JButton ("Exit");
lblWeight = new JLabel ("Enter the Weight in Kgs: ");
lblResult = new JLabel ("Result:");
txtWeight = new JTextField (10);
txtResult= new JTextField (10);
//Add all components to panel
pane.add (lblWeight);
pane.add (lblResult);
pane.add (txtWeight);
pane.add (txtResult);
pane.add (btnGrams);
pane.add (btnMilligrams);
//Set frame visible
frame1.setVisible (true);
//Button's action
lblWeight.setBounds(10,15,200,20);
pane.add(lblWeight);
lblResult.setBounds(10,160,125,25);
pane.add(lblResult);
txtWeight.setBounds(160,15,125,25);
pane.add(txtWeight);
txtResult.setBounds(70,160,125,25);
pane.add(txtResult);
btnGrams.setBounds(25, 100, 100, 25);
pane.add(btnGrams);
btnMilligrams.setBounds(170, 100, 100, 25);
pane.add(btnMilligrams);
btnExit.setBounds(140, 200, 100, 25);
pane.add(btnExit);
}
private void GramsActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(txtWeight.getText());
double w1= w*1000; //1kg = 1000 grams
txtWeight.setText(txtWeight+" "+w1); // TODO add your handling code here:
}
private void MilliActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(txtWeight.getText());
double w1= w*1000000; //1kg = 1000000 milli grams
txtResult.setText(" weqwe "+w1); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
}
Hi mga ka symb. gusto ko sanang magpatulong ma complete tong code na ito, self study kasi pero dito ako hindi ma kuha...
Code:
private void GramsActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000; //1kg = 1000 grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void MilliActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(tf1.getText());
double w1= w*1000000; //1kg = 1000000 milli grams
tf2.setText(""+w1); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
/ /paki complete po sa code yung hindi na mag error im using bluej compiler.
OUTPUT:
View attachment 254999
Thanks advance sa GUI na ako pero ang hirap ng action ng mga button. THank you.
- - - Updated - - -
Pa tulong na ayos ko dito pero sa pagconvert ako nahihirapan, ! please !
//Import packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//Main class
public class conve{
//Declare variables
private JButton plainJButton;
static JFrame frame1;
static Container pane;
static JButton btnGrams, btnMilligrams, btnExit;
static JLabel lblWeight, lblResult;
static JTextField txtWeight, txtResult;
static Insets insets;
public static void main (String args[]){
//Create the frame
frame1 = new JFrame ("Grams to Milligrams Converter");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize (320,300);
pane = frame1.getContentPane();
insets = pane.getInsets();
pane.setLayout (null);
//Create controls
btnGrams = new JButton ("Grams");
btnMilligrams = new JButton ("Milligrams");
btnExit = new JButton ("Exit");
lblWeight = new JLabel ("Enter the Weight in Kgs: ");
lblResult = new JLabel ("Result:");
txtWeight = new JTextField (10);
txtResult= new JTextField (10);
//Add all components to panel
pane.add (lblWeight);
pane.add (lblResult);
pane.add (txtWeight);
pane.add (txtResult);
pane.add (btnGrams);
pane.add (btnMilligrams);
//Set frame visible
frame1.setVisible (true);
//Button's action
lblWeight.setBounds(10,15,200,20);
pane.add(lblWeight);
lblResult.setBounds(10,160,125,25);
pane.add(lblResult);
txtWeight.setBounds(160,15,125,25);
pane.add(txtWeight);
txtResult.setBounds(70,160,125,25);
pane.add(txtResult);
btnGrams.setBounds(25, 100, 100, 25);
pane.add(btnGrams);
btnMilligrams.setBounds(170, 100, 100, 25);
pane.add(btnMilligrams);
btnExit.setBounds(140, 200, 100, 25);
pane.add(btnExit);
}
private void GramsActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(txtWeight.getText());
double w1= w*1000; //1kg = 1000 grams
txtWeight.setText(txtWeight+" "+w1); // TODO add your handling code here:
}
private void MilliActionPerformed(java.awt.event.ActionEvent evt) {
double w=Double.parseDouble(txtWeight.getText());
double w1= w*1000000; //1kg = 1000000 milli grams
txtResult.setText(" weqwe "+w1); // TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0); // TODO add your handling code here:
}
}
Attachments
Last edited: