Hallo,
ich bin grad an einem Kohleschichtwiderstandberechner und mir wurde schon mal geholfen. Da ich wieder nicht weiter weiß hoffe ich nochmal hier Hilfe zu bekommen. Das Progamm sollte etwa so aussehen:
Resistor Colour Code
Soweit erst. Nun muss das GUI erstellt und gestartet werden , doch da weiß ich nicht mehr weiter.
Muss auch zugeben, dass ich mir teilweise Hilfe geholt habe, wie im letzten Teil
.
Die Werte stimmen noch net ganz, aber mir gehts erstmal um den vorhingenannten Punkt
ich bin grad an einem Kohleschichtwiderstandberechner und mir wurde schon mal geholfen. Da ich wieder nicht weiter weiß hoffe ich nochmal hier Hilfe zu bekommen. Das Progamm sollte etwa so aussehen:
Resistor Colour Code
Java:
import java.awt.Borderlayout;
import java.awt.event.ItemListener;
import java.awt.choice;
import java.awt.color;
import java.awt.flowlayout;
import java.awt.Graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.Jframe;
import javax.swing.Jlabel;
import javax.swing.Jpanel;
Public class Resistor
{
Jframe j frame;
choice ch1;
choice ch2;
choice ch3;
choice ch4;
JLabel1 resistorImg;
JLabel1 resistorImg1;
JLabel1 display1;
JLabel1 display2;
JLabel1 display3;
JLabel1 display4;
JLabel1 result;
Color black;
Color brown;
Color orange;
Color yellow;
Color green;
Color blue;
Color violet;
Color gray;
Color white;
public static void main(string[] args)
{
new Resistor.frame();
}
void frame()
{
Jpanel1 panel1 = newJpanel();
Jpanel1 panel2 = newJpanel();
Jpanel1 panel3 = newJpanel();
jframe = new Jframe();
jframe.setTitle("Resistor code");
jframe.setSize(400, 300);
jframe.setLocation(300,200);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1 = new Jlabel {" Resistor Color Code Application"};
display1 = new Jlabel("-");
display2 = new Jlabel("-");
display3 = new Jlabel("-");
display4 = new Jlabel("-");
ch1 = new Choice();
ch2 = new Choice();
ch3 = new Choice();
ch4 = new Choice();
black = new color(0,0,0);
brown = new color(108,59,14);
red = new color (255,0,0);
orange = new color(241,180,25);
yellow = new color (251,251,17);
blue = new color(0,0,250);
violet = new color (218,16,252);
gray = new color (150,150,150);
white = new color(255,255,255);
green = new color(0,255,0);
final myDraw mdraw = new myDraw();
string[] strl = new string[10];
strl[0]= "black";
strl[1]= "brown";
strl[2]= "red";
strl[3]= "orange";
strl[4]= "yellow";
strl[5]= "green";
strl[6]= "blue";
strl[7]= "violet";
strl[8]= "gray";
strl[9]= "white";
for(int i=0; i <strl.lenght; i++)
{ch1. insert(strl[i], i);
}
ch1.addItemListener( new ItemListener()
{
public void itemStateChanged(ItemEvent arg0)
{
int select;
select = ch1.getselectedIndex();
switch(select)
{
case0: display1.setText("");
ch1.setBackground(black);
mdraw.setColor1(black);
break;
case1: display1.setText("1");
ch1.setBackground(brown);
mdraw.setColor1(brown);
break;
case2: display1.setText("2");
ch1.setBackground(red);
mdraw.setColor1(red);
break;
case3: display1.setText("3");
ch1.setBackground(orange);
mdraw.setColor1(orange);
break;
case4: display1.setText("4");
ch1.setBackground(yellow);
mdraw.setColor1(yellow);
break;
case5: display1.setText("5");
ch1.setBackground(green);
mdraw.setColor1(green);
break;
case6: display1.setText("6");
ch1.setBackground(blue);
mdraw.setColor1(blue);
break;
case7: display1.setText("7");
ch1.setBackground(violet);
mdraw.setColor1(violet);
break;
case8: display1.setText("8");
ch1.setBackground(gray);
mdraw.setColor1(gray);
break;
case9: display1.setText("9");
ch1.setBackground(white);
mdraw.setColor1(white);
break;
default:
mdraw.setcolor3(black);
break;
}
}}};
string[] str2 = new string[10];
str2[0]= "black";
str2[1]= "brown";
str2[2]= "red";
str2[3]= "orange";
str2[4]= "yellow";
str2[5]= "green";
str2[6]= "blue";
str2[7]= "violet";
str2[8]= "gray";
str2[9]= "white";
for(int x=0; x< str2.lenght; x++)
{
ch2.insert{
str2[x], x);
}
ch2.addItemListener( new ItemListener(){
public void itemStateChange(itemEvent argo){
int select;
select = ch2.getSelectedIndex();
switch(select)
{
case 0: display2.setText("0");
ch2.setBackground(black);
mdraw.setcolor2(black);
break;
case 1: display2.setText("1");
ch2.setBackground(brown);
mdraw.setcolor2(brown);
break;
case 2: display2.setText("2");
ch2.setBackground(red);
mdraw.setcolor2(red);
break;
case 3: display2.setText("3");
ch2.setBackground(orange);
mdraw.setcolor2(orange);
break;
case 4: display2.setText("4");
ch2.setBackground(yellow);
mdraw.setcolor2(yellow);
break;
case 5: display2.setText("5");
ch2.setBackground(green);
mdraw.setcolor2(green);
break;
case 6: display2.setText("6");
ch2.setBackground(blue);
mdraw.setcolor2(blue);
break;
case 7: display2.setText("7");
ch2.setBackground(violet);
mdraw.setcolor2(violet);
break;
case 8: display2.setText("8");
ch2.setBackground(gray);
mdraw.setcolor2(gray);
break;
case 9: display2.setText("9");
mdraw.setcolor2(white);
break;
}
}}};
string[] str3 = new string[10];
str3[0]= "black";
str3[1]= "brown";
str3[2]= "red";
str3[3]= "orange";
str3[4]= "yellow";
str3[5]= "green";
str3[6]= "blue";
str3[7]= "violet";
str3[8]= "gray";
str3[9]= "white";
for(int x=0; x< str3[x],
);
}
ch3.addItenListener(new ItemListener()(
public void itemStateChanged(ItemEvent arg0)
{
int select;
select = ch3.getSelectedIndex();
switch(select)
{
case 0: display2.setText("-");
ch2.setBackground(black);
mdraw.setcolor2(black);
break;
case 1: display2.setText("1");
ch2.setBackground(brown);
mdraw.setcolor2(brown);
break;
case 2: display2.setText("2");
ch2.setBackground(red);
mdraw.setcolor2(red);
break;
case 3: display2.setText("3");
ch2.setBackground(orange);
mdraw.setcolor2(orange);
break;
case 3: display2.setText("3");
ch2.setBackground(orange);
mdraw.setcolor2(orange);
break;
case 4: display2.setText("4");
ch2.setBackground(yellow);
mdraw.setcolor2(yellow);
break;
case 5: display2.setText("5");
ch2.setBackground(green);
mdraw.setcolor2(green);
break;
case 6: display2.setText("6");
ch2.setBackground(blue);
mdraw.setcolor2(blue);
break;
case 7: display2.setText("7");
ch2.setBackground(violet);
mdraw.setcolor2(violet);
break;
case 8: display2.setText("8");
ch2.setBackground(gray);
mdraw.setcolor2(gray);
break;
case 9: display2.setText("9");
mdraw.setcolor2(white);
break;
}
}}};
string[] str4 = new string[10];
str4[0]= "Black";
str3[0]= "black";
str3[1]= "brown";
str3[2]= "red";
str3[3]= "orange";
str3[4]= "yellow";
str3[5]= "green";
str3[6]= "blue";
str3[7]= "violet";
str3[8]= "gray";
str3[9]= "white";
for(int x=0; x< str4.length; x++)
{
ch4.insert(str4[x], x);
}
}
Ch4.addItemListener(new itemListener(){
public void itemStateChanged(ItemEvent arg0)
{
int select;
select = ch4.getSelectedIndex();
switch(select)
{
case 0: display2.setText("oomuint");
ch2.setBackground(black);
mdraw.setcolor2(black);
break;
case 1: display2.setText("0oomuint");
ch2.setBackground(brown);
mdraw.setcolor2(brown);
break;
case 2: display2.setText("koomuint");
ch2.setBackground(red);
mdraw.setcolor2(red);
break;
case 3: display2.setText("okoomuint");
ch2.setBackground(orange);
mdraw.setcolor2(orange);
break;
case 3: display2.setText("00koomunit");
ch2.setBackground(orange);
mdraw.setcolor2(orange);
break;
case 4: display2.setText("Moommunit");
ch2.setBackground(yellow);
mdraw.setcolor2(yellow);
break;
case 5: display2.setText("0oomunnit");
ch2.setBackground(green);
mdraw.setcolor2(green);
break;
case 6: display2.setText("moomuint");
ch2.setBackground(blue);
mdraw.setcolor2(blue);
break;
case 7: display2.setText("omunit");
ch2.setBackground(violet);
mdraw.setcolor2(violet);
break;
case 8: display2.setText("-");
ch2.setBackground(gray);
mdraw.setcolor2(gray);
break;
case 9: display2.setText("-");
mdraw.setcolor2(white);
break;
}
}}};
panel1.setBackground(color.white);
panel2.setBackground(color.white);
panel3.setBackground(color.white);
panel1.setBorder(borderFactory.createLowerdbevelborder()};
panel3.setBorder(borderFactory.createLowerdbevelborder()};
panel1.setLayOUT( NEW bORDERlAYOUT());
panel1.add( (new BorderLayout().NORTh,11);
panel12.setLayout(new flowLayout());
panel12.add(ch1);
panel12.add(ch2);
panel12.setLayout( new FlowLayout());
panel12.add(ch1);
panel12.add(ch2);
panel12.add(ch3);
panel12.add(ch4);
panel1.add((new BorderLayout().south, panel12);
panel13.add((new BorderLayout().center, display1);
panel13.add((new BorderLayout().center, display2);
panel13.add((new BorderLayout().center, display3);
panel13.add((new BorderLayout().center, display4);
jframe.getcontentpane().add( new BorderLayout().north, panel1);
jframe.getcontentpane().add( new BorderLayout().center, panel1);
jframe.getcontentpane().add( new BorderLayout().south, panel1);
jframe.setBackground(Color.white);
jframe.setvisible(true);
}
}
class myDraw extends Jpanel{
private color color1;
private color color2;
private color color3;
private color color4;
public void paintcomponent(Graphics g)
{
g.setColor(color.white);
g.fillrect(0,0, this.getwidth(),this.getHeight());
this.repaint();
g.setColor(color.LIGHT_GRAY);
g.fillRoundRect(this.getWidth()/2-75, this.getHeight()/2-40, 150, 80, 20, 20);
g.fillRoundRect(this.getWidth()/2-90, this.getHeight()/2-50, 90, 100, 15, 15);
g.fillRoundRect(this.getWidth()/2+65, this.getHeight()/2-50, 30, 100, 15, 15);
g.getColor(color1));
g.fillRoundRect(this.getwIDTH()/2-25, THIS.GetHeight()/2-40,10,80, 10, 10);
g.getColor(color2));
g.fillRoundRect(this.getwIDTH()/2-20, THIS.GetHeight()/2-40,10,80, 10, 10);
g.getColor(color3));
g.fillRoundRect(this.getwIDTH()/2+18, THIS.GetHeight()/2-40,10,80, 10, 10);
g.getColor(color4));
g.fillRoundRect(this.getwIDTH()/2+45, THIS.GetHeight()/2-40,10,80, 10, 10);
g.setColor(color.black);
g.fillDrect(this.getwidth()/2-145, this.getHeight()/ 2,55,5, true);
g.fillDrect(this.getwidth()/2+95, this.getHeight()/ 2,55,5, false);
g.fillDrect(this.getwidth()/2+145, this.getHeight()/ 2,5,50, false);
g.fillDrect(this.getwidth()/2-145, this.getHeight()/ 2,5,50, true);
}
Soweit erst. Nun muss das GUI erstellt und gestartet werden , doch da weiß ich nicht mehr weiter.
Muss auch zugeben, dass ich mir teilweise Hilfe geholt habe, wie im letzten Teil
Die Werte stimmen noch net ganz, aber mir gehts erstmal um den vorhingenannten Punkt