Open hazrulm opened 9 years ago
package bengproject;
import java.awt.*; import java.util.List; import javax.swing.JPanel;
class GraphPanel extends JPanel {
/*
*
/
private static final long serialVersionUID = 1L;
private List
public GraphPanel() {
setBackground(Color.WHITE);
setSize(500, 100);
}
public void setInputSignal(List<Integer> inputSignal) {
this.inputSignal = inputSignal;
}
private void drawInputSignal(Graphics2D g2d) {
int x = 0;
int y;
int oldY = 0;
for(Integer i : inputSignal) {
y = getHeight(i);
// code for drawing vertical lines
if (x > 0) {
g2d.drawLine(x, oldY, x, y);
}
oldY = y;
g2d.drawLine(x, y, x + INTERVAL, y);
x += INTERVAL;
}
}
private int getHeight(int value) {
switch(value) {
case 1:
return HEIGHT;
case 0:
return HEIGHT/2;
case -1:
return 0;
}
throw new RuntimeException("Invalid value");
}
private void doDrawing(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
drawInputSignal(g2d);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
package bengproject; /*
import java.awt.; import javax.swing.; import java.awt.event.; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import java.util.List; /
@author Hazrul Muhammad / public class CDMA extends JFrame { /*
*/ private static final long serialVersionUID = 1L; private final JLabel label1, label2, label3; private final JTextField textField1;
//set up GUI public CDMA() { setTitle("CDMA");
// System.out.println( binary.);
} /**
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
//private inner class for event handling public class TextFieldHandler implements ActionListener {
} }