Resistor calculator

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

42 Replies - 4908 Views - Last Post: 02 August 2010 - 05:37 PM Rate Topic: -----

#1 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Resistor calculator

Posted 21 July 2010 - 08:13 PM

Hi there, i am new to java programming.
currently using Netbeans to compile my java programs,
i have an assignment on creating a program which calculates The resistor value
by choosing the different colours on it, any help?
on how i can start and what i need to use?
if you could give me a sample i can follow up on it

Thank you guys!
much appreciated!
Is This A Good Question/Topic? 0
  • +

Replies To: Resistor calculator

#2 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Resistor calculator

Posted 21 July 2010 - 08:24 PM

You will need to show some code for us to help you, but meanwhile if you're looking for an example, this is the first link on Google, it looks like something you might model after:

http://www.dannyg.co...s2/resistor.htm
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Resistor calculator

Posted 21 July 2010 - 08:28 PM

If you used NetBeans it means you wrote some code :) We will be glad to see it

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#4 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Resistor calculator

Posted 21 July 2010 - 10:58 PM

Things that you will need

a class
a main method
2 variables ( i assume you are using V=IR to calculate resistance )
a System.out.println(V/I) statement to display the result

Hope this Helps. :bigsmile:

This post has been edited by Crunch: 21 July 2010 - 11:05 PM

Was This Post Helpful? 0
  • +
  • -

#5 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 21 July 2010 - 11:57 PM

hi guys,

i have a rough on idea on how to start,
the end user just clicks/selects the colour
and it automatically calculates and gives the value

i am new to java and i dont know where to start from!

thanks guys
Was This Post Helpful? 0
  • +
  • -

#6 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Resistor calculator

Posted 22 July 2010 - 12:01 AM

You will want to use JComboBoxes with actionListeners to provide colors and determine when the user selects a different color.

As soon as your action listener notifies you of a new color being selected, you can do your calculations and output the result, whatever it may be, in whatever form best suits you.
Was This Post Helpful? 1
  • +
  • -

#7 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 22 July 2010 - 01:36 AM

View Postbcranger, on 21 July 2010 - 11:01 PM, said:

You will want to use JComboBoxes with actionListeners to provide colors and determine when the user selects a different color.

As soon as your action listener notifies you of a new color being selected, you can do your calculations and output the result, whatever it may be, in whatever form best suits you.



hey there thanks alot for the tips !
i have started off my coding , so far so good!
Was This Post Helpful? 0
  • +
  • -

#8 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 26 July 2010 - 03:14 AM

Hi Java GURUS!,

this is so far what i have wrote,
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JResistor extends JFrame
{

        private JButton jbtResult = new JButton("Result");
        private JComboBox jcboColor = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White"});
        private JComboBox jcboColor2 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White"});
        private JComboBox jcboColor3 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White","BLANK"});
        private JComboBox jcboColor4 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White","gold","silver"});
        private JComboBox jcboColor5 = new JComboBox(new String[]{"gold","silver"});


        private JButton jbtResult1 = new JButton("Band1");
        private JButton jbtResult2 = new JButton("Band2");
        private JButton jbtResult3 = new JButton("Band3");
        private JButton jbtResult4 = new JButton("Multiplier");
        private JButton jbtResult5 = new JButton("Tolerance");



    public JResistor()
    {
      

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(1,5));
        panel.add(jcboColor);
        panel.add(jcboColor2);
        panel.add(jcboColor3);
        panel.add(jcboColor4);
        panel.add(jcboColor5);

        JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayout(1,5));
        panel2.add(jbtResult1);
        panel2.add(jbtResult2);
        panel2.add(jbtResult3);
        panel2.add(jbtResult4);
        panel2.add(jbtResult5);

        JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayout(2,1));
        panel3.add(panel);
        panel3.add(panel2);

        this.add(panel3,BorderLayout.CENTER);
        this.add(jbtResult, BorderLayout.WEST);
        

    }
    





    public static void main(String[] args)
    {



        JResistor frame = new JResistor();
        frame.setTitle("resistor decoder");
        frame.setSize(550,100);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}



can anyone help with the background of the Jcombobox, i want it to Coincide with the words, like Green shold have a Green background

Edited by macosxnerd101: Welcome to DIC! :) Please, :code:.
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,467
  • Joined: 27-December 08

Re: Resistor calculator

Posted 26 July 2010 - 04:26 AM

Take a look at the JComboBox class. It inherits the setBackground() method from JComponent.
Was This Post Helpful? 0
  • +
  • -

#10 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 26 July 2010 - 08:11 AM

View Postmacosxnerd101, on 26 July 2010 - 03:26 AM, said:

Take a look at the JComboBox class. It inherits the setBackground() method from JComponent.



hi could you like show me an example of the code?
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,467
  • Joined: 27-December 08

Re: Resistor calculator

Posted 26 July 2010 - 08:13 AM

The setBackground() method accepts a Color object as a param, so you'll need to pass one to it. Below are a couple examples including creating a new Color object and using an existing constant in the Color class.
myJComboBox.setBackground(new Color(50,20,100)); //sets background to new Color object
myJComboBox.setBackground(Color.BLUE); //sets background to predefined Color object


Was This Post Helpful? 0
  • +
  • -

#12 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 26 July 2010 - 09:19 AM

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JResistor extends JFrame
{

        private JButton jbtResult = new JButton("Result");
        private JComboBox jcboColor = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White"});
        private JComboBox jcboColor2 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White"});
        private JComboBox jcboColor3 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White","BLANK"});
        private JComboBox jcboColor4 = new JComboBox(new String[]{"Black","Brown","Red",
        "Orange","Yellow","Green","Blue","violet","Grey","White","gold","silver"});
        private JComboBox jcboColor5 = new JComboBox(new String[]{"gold","silver"});
        
        private JButton jbtResult1 = new JButton("Band1");
        private JButton jbtResult2 = new JButton("Band2");
        private JButton jbtResult3 = new JButton("Band3");
        private JButton jbtResult4 = new JButton("Multiplier");
        private JButton jbtResult5 = new JButton("Tolerance");


    public JResistor()
    {
      

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(1,5));
        panel.add(jcboColor);
        panel.add(jcboColor2);
        panel.add(jcboColor3);
        panel.add(jcboColor4);
        panel.add(jcboColor5);

        JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayout(1,5));
        panel2.add(jbtResult1);
        panel2.add(jbtResult2);
        panel2.add(jbtResult3);
        panel2.add(jbtResult4);
        panel2.add(jbtResult5);

        JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayout(2,1));
        panel3.add(panel);
        panel3.add(panel2);

        this.add(panel3,BorderLayout.CENTER);
        this.add(jbtResult, BorderLayout.WEST);
        

    }
    

    public static void main(String[] args)
    {
        JResistor frame = new JResistor();
        frame.setTitle("resistor decoder");
        frame.setSize(550,100);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}




this is my code so far,
how can i replace
private JComboBox jcboColor2 = new JComboBox(new String[]{"Black","Brown","Red",
"Orange","Yellow","Green","Blue","violet","Grey","White"});
with COLOURS rather than words such as "black" or "Green"

Edited by macosxnerd101: Please, :code:.
Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,467
  • Joined: 27-December 08

Re: Resistor calculator

Posted 26 July 2010 - 09:25 AM

Duplicate topics merged. Please avoid duplicate posting.

You'll have to write a custom ListCellRenderer for your JComboBox in order for it to display colors. The Sun Tutorial covers more on custom ListCellRenderers.
Was This Post Helpful? 0
  • +
  • -

#14 Nesh_27  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 21-July 10

Re: Resistor calculator

Posted 26 July 2010 - 09:44 AM

not helping
Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,467
  • Joined: 27-December 08

Re: Resistor calculator

Posted 26 July 2010 - 09:45 AM

Is there something you don't understand? Can you expand on what additional help you need?
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3