import javax.swing.*; import java.awt.*; /* * Created on Jan 26, 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author User * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class ChannelPanel extends JPanel { int x1 = 10,y1 = 220; int margin = 10; int width = 200; int depth = 100; int roughnessDepth = 10; public double ratio = 0.0; int length = 200; double theta = Math.PI/3.0; int xOffset = (int)(length*Math.cos(theta)); int yOffset = (int)(length*Math.sin(theta)); int ySurfaceOffset = (int)(ratio*width); int[] x = {x1,x1+width,x1+width+xOffset,x1+xOffset}; int[] yTop = {y1,y1,y1-yOffset,y1-yOffset}; int[] yBottom = {y1+depth, y1+depth, y1+depth-yOffset, y1+depth-yOffset}; int[] yRoughness = {y1+depth-margin, y1+depth-margin, y1+depth-margin-yOffset, y1+depth-margin-yOffset}; int[] ySurface = {y1+depth-margin-ySurfaceOffset, y1+depth-margin-ySurfaceOffset, y1+depth-margin-yOffset-ySurfaceOffset, y1+depth-margin-yOffset-ySurfaceOffset}; public void paintComponent(Graphics g) { int d = (int)(ratio*width); Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(1.0f)); g2.setColor(new Color(160,82,45)); g2.fillPolygon(x, yRoughness, 4); g2.fillRect(x1, y1+depth-margin, width, margin); g2.fillRect(x1+xOffset,y1-yOffset+depth-margin,width, margin); g2.fillPolygon(x, yBottom, 4); g2.setColor(Color.BLACK); g2.drawPolygon(x, yRoughness, 4); g2.drawRect(x1, y1+depth-margin, width, margin); g2.drawRect(x1+xOffset,y1-yOffset+depth-margin,width, margin); g2.drawPolygon(x, yBottom, 4); ySurfaceOffset = (int)(ratio*width); ySurface[0] = y1+depth-margin-ySurfaceOffset; ySurface[1] = y1+depth-margin-ySurfaceOffset; ySurface[2] = y1+depth-margin-yOffset-ySurfaceOffset; ySurface[3] = y1+depth-margin-yOffset-ySurfaceOffset; if(Math.abs(ySurfaceOffset) >= 0.5){ g2.setColor(Color.BLUE); g2.fillPolygon(x, ySurface, 4); } g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(2.0f)); g2.drawPolygon(x, yTop, 4); g2.drawPolygon(x, yBottom, 4); g2.drawRect(x1, y1, width, depth); g2.drawRect(x1+xOffset,y1-yOffset,width, depth); } }