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!

<h1>Java Expert {I need Your Help};<h1>

softechexpert

Proficient
Advanced Member
Messages
248
Reaction score
0
Points
26
&lt;h1&gt;Java Expert {I need Your Help};&lt;h1&gt;

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

  • 3 (1).gif
    3 (1).gif
    9 KB · Views: 9
Last edited:
Back
Top Bottom