Skip to main content

Intro To Programming Help Please

1 reply [Last post]
Brandonbs22
Offline
Joined: 2013-04-02
Points: 0

ok so i need help with is assigment http://programming.msjc.edu/java/assignments/midterm/midterm.html

my question is how would i get the color to show at the bottom like the example and how do i get the percent of the hex? This is what i got so far. Please help this is nothing for u guys. not trying to get free hw, but i just want to learn and need help. Thanks

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

public class Midterm extends JApplet implements ActionListener

{
JLabel lblRedNum = new JLabel();
JLabel lblGrnNum = new JLabel();
JLabel lblBluNum = new JLabel();
JLabel lblRedDec = new JLabel();
JLabel lblGrnDec = new JLabel();
JLabel lblBluDec = new JLabel();
JLabel lblColor = new JLabel("Color");
JTextField tfRed = new JTextField(10);
JTextField tfGrn = new JTextField(10);
JTextField tfBlu = new JTextField(10);
JButton btnColor = new JButton("Show Color");

Container content = this.getContentPane();

public void init()
{
content.setLayout(new GridLayout(5,3));
content.add(new JLabel("Red"));
content.add(new JLabel("Green"));
content.add(new JLabel("Blue"));
content.add(tfRed);
content.add(tfGrn);
content.add(tfBlu);
content.add(lblRedNum);
content.add(lblGrnNum);
content.add(lblBluNum);
content.add(lblRedDec);
content.add(lblGrnDec);
content.add(lblBluDec);
content.add(btnColor);
content.add(lblColor);
btnColor.addActionListener(this);

}

@Override
public void actionPerformed(ActionEvent e)
{

int numr = Integer.valueOf(tfRed.getText(), 16);
lblRedDec.setText("" + numr);

int numg = Integer.valueOf(tfGrn.getText(), 16);
lblGrnDec.setText("" + numg);

int numb = Integer.valueOf(tfBlu.getText(), 16);
lblBluDec.setText("" + numb);

}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MackSix
Offline
Joined: 2013-03-27
Points: 0

First you need to learn how to post formatted code with the <> button so it wraps it in pre tags.