/* Bezier Spline basis calulations for 4 point Bezier Curves */ package com.bestwaveslive ; import java.awt.*; public class Bezier { private Point[] points; private static final int CIRCLE_WIDTH = 4; public Bezier(Point[] points ){ this.points = points; } Font currentFont ; void updayteG(int xplus, int yplus){ points[1].x -= xplus ; points[1].y += yplus ; } void updayteH(int yplus){ points[2].y += yplus ; } void paint(Graphics g, int ft, boolean dl){ Rectangle rect = g.getClipBounds(); int height = rect.height ; currentFont = new Font("Arial", Font.PLAIN,14); g.setFont(currentFont); int jXpt = 0; int jYpt = 0; int vXpt = 0; int vYpt = 0, numbspace = 0 ; // boolean drawornot = dl ; // Draw the control points if(dl ){ g.setColor(new Color(0, 0, 0)); // was red int ijp = ft ; for(int i = 0 ; i < 4; i++){ g.drawOval(points[i].x, (height - points[i].y), CIRCLE_WIDTH, CIRCLE_WIDTH); String sn = Integer.toString(i+ijp); if(((i+ijp)%2)==1 ){ // number is odd numbspace = 10 ; }else{ numbspace = 0 ; } g.drawString(sn, points[i].x-numbspace, (height - points[i].y)); } // Draw the lines for the control points g.setColor(new Color(200, 200, 200)); g.drawLine(points[0].x, (height - points[0].y), points[1].x, (height - points[1].y)); g.drawLine(points[1].x, (height - points[1].y), points[2].x, (height - points[2].y)); g.drawLine(points[2].x, (height - points[2].y), points[3].x, (height - points[3].y)); } // if(dl) // Draw the curves g.setColor(new Color(0, 0, 0)); for(double incr = 0; incr <= 1.02; incr += 0.02){ // Find the X coordinate using the // Bezier functions jXpt = (int) ((bezpwr1(incr) * points[0].x) + (bezpwr2(incr) * points[1].x) + (bezpwr3(incr) * points[2].x) + (bezpwr4(incr) * points[3].x)); // Find the Y coordinate, using the // Bezier functions jYpt = (int) ((bezpwr1(incr) * points[0].y) + (bezpwr2(incr) * points[1].y) + (bezpwr3(incr) * points[2].y) + (bezpwr4(incr) * points[3].y)); if(incr != 0){ // drawLine is used because Java does not have // a pixel drawing function g.drawLine(vXpt, (height -vYpt), jXpt, (height -jYpt)); } // if(incr != 0 vXpt = jXpt; vYpt = jYpt; } // for(double t = 0 jXpt = 0; jYpt = 0; vXpt = 0; vYpt = 0; } //paint() function double bezpwr1(double incr){ return Math.pow((1.0 - incr), 3); } double bezpwr2(double incr){ return (3.0 * incr * Math.pow((1.0 - incr), 2)); } double bezpwr3(double incr){ return (3.0 * Math.pow(incr, 2) * (1.0 - incr)); } double bezpwr4(double incr){ return Math.pow(incr, 3); } } // E.O.P. package com.bestwaveslive ; import java.awt.Graphics; public class Bezier2 { com.bestwaveslive.Bezier bezierG, bezierH; boolean dl ; Bezier2(com.bestwaveslive.Bezier bezierG, com.bestwaveslive.Bezier bezierH, boolean dl) { this.bezierG = bezierG; this.bezierH = bezierH; this.dl = dl ; } void paint(Graphics g) { bezierG.paint(g, 0, dl); bezierH.paint(g, 4, dl); } } /** * Wave.java Does preliminary math for breaking wave control points. * * @author William Redelmeier */ /* Created in 2007, 2008 * * 2* 3* *4 * ____ /|\ * _____/ | \ * _____/ | \ * _____/ | \ * ___/ | \ * /____________________________|___________\ * 0* 1* 5* * * Bezier Control points, 2 sets At the start, before rotation. * Curve not depicted. * * 2* * * 3* * ___/\ * _ _____/ | \ *4 * _______/ | \ * _____/ | \ * _______/ | \ * /____________________________|___________\ *0* 1* 5* * * Bezier Control points, 2 sets At the start, after rotation Curve not depicted */ package com.bestwaveslive ; import java.awt.Point; public class Wave { protected double xwd = 0.0, yht = 0.0; public int ihorizscr = 40; double phaseincr = .029;// increase of angle was .08 public double phaserads = 1.601; //alphincr * -1.0; // Angle 1.601 double phaseend = 1.35; // greatest possible angle 1.41 // in radian measure, 0 is vertical - resets to it int BW = 10; // was 4; // Bulk width in pixels int BWincr = 3; //was 4; // decrease of BW - wave shoulder volatile int BWstart; // = 0 ; int hWvLen = 0; int BWend = 0; int startval; //= sliderst.getValue(); int endval; // from sliders 3,5 Bezier bezierG, bezierH; Point[] pts; int ilev1; // base, lev2 is starting height static int wdth, hght; // 600,400 Point[] gpts = new Point[4]; Point[] hpts = new Point[4]; int lrMotAcc = 0; int lrMot = 7; // = 8 ; void setwdth(int wdth) { Wave.wdth = wdth; // System.out.println("In Wave, wdth is "+wdth); // 600 } void sethght(int hght) { Wave.hght = hght; // (int)(lev2 - lev1) } int gethght() { // return(pts[5].x - (int)(lev1)); // probably should be return (hght); } int getwdth() { return (Wave.wdth); } public Point[] getPts() { return pts; } public Wave(int w, int h, int startval, int endval) { this.setwdth(w); this.sethght(h); pts = new Point[6]; // double xwd, yht ; xwd = (double) wdth; // was w yht = (double) hght; // was h BWstart = BWstcalc(startval); //(int)(.503 * xwd); // numframes = (int) (alphend / alphincr); // System.out.println("xwd is " + xwd); // System.out.println("yht is " + yht); double lev1 = (yht * 0.26); // was .46 double lev2 = (yht * 0.63); // was .73 ilev1 = (int) (lev1); int ilev2 = (int) (lev2); // System.out.println("ilev2 is " + ilev2); // 46 bezierG = new com.bestwaveslive.Bezier(gpts); bezierH = new com.bestwaveslive.Bezier(hpts); phaseincr = .032;// increase of angle was .08 phaserads = 1.601; // alphincr * -1.0; // Angle 1.601 phaseend = 1.38; // greatest possible angle // in radian measure, 0 is vertical - resets to it BW = 4; // Bulk width in pixels BWincr = 4; // decrease of BW - wave shoulder // BWstart = 0 ; // hWvLen = 0 ; // BWend = 0 ; pts = new Point[6]; double xwd, yht; /* * if (incrflag == 1) { BWincr = BWincrSet(endval); incrflag = 0; } */ xwd = (double) getwdth(); //wdth ; yht = (double) gethght(); //hght ; // proportional to the monitor's size pts[0] = new Point((int) (xwd * 0.0), (int) (yht * 0.56)); pts[1] = new Point((int) (xwd * 0.225), (int) (yht * 0.56)); pts[2] = new Point((int) (xwd * 0.17), (int) (yht * 0.83)); pts[3] = new Point((int) (xwd * 0.225), (int) (yht * 0.83)); pts[4] = new Point(BWstart, (int) (yht * 0.83)); // 5 pts[5] = new Point((int) (xwd * 0.45), (int) (yht * 0.56)); } // end of Wave constructor // Gets initial value of point 5 from slider int BWstcalc(int startval) { //System.out.println("1 startval is " + startval); int ichange, retval; ichange = startval; ichange -= 3; // -3 to +3 ichange *= getwdth(); //System.out.println("2 startval is " + startval); ichange /= ihorizscr; //System.out.println("2 ichange is " + ichange); retval = (int) (0.303 * getwdth()); // ? retval += ichange; return (retval); } } // E.O.P. /* */ /** * @author William Redelmeier */ package com.bestwaveslive ; import java.awt.*; import java.awt.Graphics; import java.awt.Point; import java.awt.event.*; import java.applet.*; import javax.swing.*; import javax.swing.event.*; // import java.swt.jar ; // import layout.*; // import widgets.*; public class WaveBezier extends Applet { // public static boolean appletflag = true ; protected SliderPanel sp; public JSlider sliderst; // could be an array ; public JSlider sliderend; public Container container ; public JRadioButton rButton ; public JRadioButton rbdrawlines ; public JRadioButton rbnotdraw ; protected WavePanel dp; boolean ok = true; // flags for sliders boolean mStopRequest = false; boolean runonce = true; // ! public boolean dl ; // draw lines or not final double rndup = 0.55; int ischanged = 1; int incrflag = 1; int ipArea = 0; int lmw = 0; //left most wave int nwaves = 4; public static int width; public static int height; public Wave waves[] = new Wave[nwaves]; Bezier2 wb; // [] = new Bezier2[4] ; boolean firsttime = true; boolean fpp = false; // first past the post // wwindex is the wave that the sliders change int wwindex = 1; int pos1, pos2, pos3, pos4; public WaveBezier(int width, int height) { } public WaveBezier() { } public static void main(String[] args) { // ScreenResSelector SS = new ScreenResSelector(); // DisplayMode mode = ScreenResSelector.showSelectionDialog(); // if(mode == null){ // System.err.println("No display mode selected."); // }else{ // appletflag = false ; width = 600; // = mode.getWidth(); // 600 height = 400; // = mode.getHeight(); // } WaveBezier bez = new WaveBezier(width, height); Frame frame = new Frame(); // mode.getWidth(), frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); bez.init(); frame.add("Center", bez); frame.setSize(width, height); //, 600,400); //mode.getWidth(),(int)(dslpht*mode.getHeight())); 600, 400); frame.setResizable(false); frame.setTitle("WaveBezier.java Demo"); frame.setVisible(true); } // main() public void init() { // if(appletflag){ width = 600; height = 400; // } this.setSize(width, height); this.setBackground(Color.white); this.setLayout(new BorderLayout()); SliderPanel sp = new SliderPanel(); sp.setSize(width, (int) (.25 * height));//600,50); this.add(sp, BorderLayout.SOUTH); sp.setVisible(true); int sval = sliderst.getValue(); int eval = sliderend.getValue(); for (int i = 0; i < waves.length; i++) { waves[i] = new Wave(width, height - 100, sval, eval); } // transform(); dp = new WavePanel(waves); pos1 = (int) (width * 0.28); pos2 = (int) (width * 0.33); pos3 = (int) (width * 0.42); pos4 = (int) (width * 0.45); dp.setSize(width, (int) (height * .75)); this.add(dp, BorderLayout.CENTER); dp.setVisible(true); } // end of init() class WavePanel extends Panel { private Image mOffScreenImage; private int mWidth = -1; private int mHeight = -1; public WavePanel(Wave[] pwaves) { } public void paint(Graphics g) { // String Sindex = new String(Integer.toString(wwindex)); // g.drawString("wwindex is "+ Sindex, 20,20 ); int sval, endval; int wvl = waves.length; int dummy = lmw; // wwindex - 1 ; // was +1 if (dummy == -1) { dummy = wvl; } for (int i = 0; i < (wvl - 1); i++, dummy++) { // checks for first series of waves if ((i == wwindex) && firsttime) { break; } // if if (dummy >= wvl) { dummy = 0; } if (i == (wvl - 2)) { firsttime = false; } // if // checks next wave to draw if ((waves[dummy].pts[0].x > pos1) && // 170 (waves[dummy].pts[0].x < pos2)) { // 200 fpp = true; } if ( // (firsttime == true ) && (waves[dummy].pts[0].x > pos3) && // 250 (waves[dummy].pts[0].x < pos4) && // 270 fpp == true) { fpp = false; if (ischanged == 1 && (firsttime == true)) { sval = sliderst.getValue(); waves[wwindex].BWstart = waves[wwindex] .BWstcalc(sliderst.getValue()); } if (incrflag == 1 && (firsttime == true)) { endval = sliderst.getValue(); waves[wwindex].endval = sliderend.getValue(); } /* * int eval = sliderend.getValue() ; * waves[wwindex] = new * Wave(width, height-100,sval, eval ); */ wwindex++; if (wwindex >= wvl) { wwindex = 0; } // if } // if // checks for end of rotation if ( // ( firsttime == false ) && (waves[dummy].phaserads > waves[dummy].phaseend)) { sval = sliderst.getValue(); endval = sliderend.getValue(); waves[dummy] = new Wave(width, height - 100, sval, endval); waves[dummy].phaserads = waves[dummy].phaseincr * -1.0; waves[dummy].lrMotAcc = 0; //(int)(-1.0 * waves[dummy].lrMot // ); waves[dummy].BW = 4; waves[dummy].hWvLen = (int) (0.225 * waves[dummy].getwdth()); waves[dummy].startval = sliderst.getValue(); waves[dummy].endval = sliderend.getValue(); lmw++; if (lmw >= wvl) { lmw = 0; } incrflag = 0; ischanged = 0; // getwdth s/b in WaveBezier, magic number 250 }// if waves[dummy].phaserads += waves[dummy].phaseincr; waves[dummy].lrMotAcc += waves[dummy].lrMot; reset(waves[dummy]); BWreset(waves[dummy]); Bezier2 wb = rotate(waves[dummy].phaserads, waves[dummy]); wb.paint(g); } // for } // paint( ) // Gets initial value of point 5 from slider int BWstcalc(int startval, Wave wv) { // System.out.println("1 startval is " + startval); int ichange, retval; ichange = startval; ichange -= 3; // -3 to +3 ichange *= wv.getwdth(); // System.out.println("2 startval is " + startval); ichange /= wv.ihorizscr; // System.out.println("2 ichange is " + ichange); retval = (int) (0.303 * wv.getwdth()); // ? retval += ichange; return (retval); } // BWstcalc( ) int calcArea(Wave wv) { int xbase, yheight; double adjy = 0, hght = 0, degangle; int wArea = 0; // Calculate area of triangle 1/2 base * height xbase = (int) ((wv.pts[1].x + wv.pts[5].x) / 2 + .5); xbase -= wv.pts[0].x; xbase /= 2; degangle = (1.57 - wv.phaserads); hght = Math.sin(degangle); // in radians hght *= (wv.pts[3].y - wv.pts[0].y); hght += 0.5; // if 5 lower than 3,4 - larger area if (wv.pts[4].y < (wv.pts[3].y - 10)) { adjy = (wv.pts[3].y - wv.pts[4].y) * 0.8; // Empirical } // if // if 5 higher than 3,4 - smaller area if (wv.pts[4].y > (wv.pts[3].y)) { adjy = -1.0 * ((wv.pts[4].y - wv.pts[3].y) * 0.5); // 0.6 } // if yheight = (int) (hght) + (int) adjy; // - ilev wArea = xbase * yheight; return wArea; } // end of calcArea void reset(Wave wv) { wv.pts = new Point[6]; double xwd, yht; // System.out.println("In reset, startval is " + // wv.startval); wv.BWincr = BWincrSet(wv.endval); xwd = (double) wv.getwdth(); //wdth ; yht = (double) wv.gethght(); //hght ; // proportional to the monitor's size // was yht + 0.11 wv.pts[0] = new Point((int) (xwd * 0.0), (int) (yht * 0.45)); // 0.56 wv.pts[1] = new Point((int) (xwd * 0.225), (int) (yht * 0.45)); // 0.56 wv.pts[2] = new Point((int) (xwd * 0.21), // 0.17 (int) (yht * 0.72)); // 0.83 wv.pts[3] = new Point((int) (xwd * 0.225), (int) (yht * 0.72)); // 0.83 wv.BWstart += 0.12 ; wv.pts[4] = new Point(wv.BWstart, (int) (yht * 0.72)); // 0.83 wv.pts[5] = new Point((int) (xwd * 0.45), (int) (yht * 0.45)); // 0.56 } //end of reset function Bezier2 rotate(double alpha, Wave wv) { //, Point[] pts){ double dx2, dy2; double hyp, rad; int x1, y1; int lrmot = 3; // new - l to r motion // Point[] gpts = new Point[4]; // Point[] hpts = new Point[4]; x1 = wv.pts[1].x; y1 = wv.pts[1].y; // Loop goes in here for (int i = 2; i < 5; i++) { dx2 = wv.pts[i].x - x1; dy2 = wv.pts[i].y - y1; hyp = Math.sqrt(dx2 * dx2 + dy2 * dy2) + rndup; rad = Math.atan2(dy2, dx2); rad = rad - alpha; dx2 = hyp * Math.cos(rad) + rndup; dy2 = hyp * Math.sin(rad) + rndup; wv.pts[i].x = (int) (dx2 + rndup); wv.pts[i].x += x1; wv.pts[i].y = (int) (dy2 + rndup); wv.pts[i].y += y1; } // for loop ends here WaveLenSet(wv); // Clipping pts[4] int cliplev = (int) (height * .56); if (wv.pts[4].y <= cliplev) { double m = 1; // if line is vertical // if(wv.pts[2].x == wv.pts[4].x ){ // wv.pts[4].y = cliplev ; // }else{ m = (wv.pts[3].y - wv.pts[2].y); m /= (wv.pts[3].x - wv.pts[2].x); wv.pts[4].x += (int) ((cliplev - wv.pts[4].y) / m); wv.pts[4].y = cliplev; } // if // Collar on 5, could also clip // substitute pts[3] for pts[2], below if (wv.pts[4].y > wv.pts[2].y) { wv.pts[4].y = wv.pts[2].y; wv.pts[4].x = wv.pts[2].x; } // if ipArea = calcArea(wv); int dummyArea = ipArea; int g1x, g1y, h2x, h2y; g1x = wv.pts[1].x; g1y = wv.pts[1].y; h2x = wv.pts[1].x; h2y = wv.pts[1].y; // int puffsearly = 7800 ; // int puffslate = 7500 ; int krs = 4; // puffs up more while (dummyArea < 7000) { // was 7500,8000 g1x -= 7; g1y += 2; h2x += krs; h2y += 7; dummyArea += 600; if (dummyArea > 1200) { //was 1200 krs = 1; } // if }// while The above can be optimized, but... // Add lrmot to all points' x value // for motion from left to right wv.pts[0].x += wv.lrMotAcc; wv.pts[2].x += wv.lrMotAcc; wv.pts[3].x += wv.lrMotAcc; wv.pts[4].x += wv.lrMotAcc; wv.pts[5].x += wv.lrMotAcc; g1x += wv.lrMotAcc; h2x += wv.lrMotAcc; wv.gpts[0] = wv.pts[0]; wv.gpts[1] = new Point(g1x, g1y); wv.gpts[2] = wv.pts[2]; wv.gpts[3] = wv.pts[3]; wv.hpts[0] = wv.pts[3]; //4 wv.hpts[1] = wv.pts[4]; //5 wv.hpts[2] = new Point(h2x, h2y); wv.hpts[3] = wv.pts[5]; // bezierG = new Bezier(gpts); // bezierH = new Bezier(hpts); return new Bezier2(new Bezier(wv.gpts), new Bezier(wv.hpts), dl ); } // rotate void BWreset(Wave wave) { wave.BW += wave.BWincr; wave.pts[4].x += wave.BW; // number 5 point changing if (wave.hWvLen > (int) (0.15 * wave.getwdth())) { wave.hWvLen *= -1; } // if // wavelength shrinking } // BWreset int BWincrSet(int endval) { waves[wwindex].BWincr = (waves[wwindex].endval - 5); return waves[wwindex].BWincr; } // BWincrSet() void WaveLenSet(Wave wave) { // called in rotate() int xLe = 0, xRe = 0; // hWvLen = (int)(0.225*getwdth()) ; int xmid = (int) (wave.getwdth() * 0.225); xLe = (int) (xmid - wave.hWvLen); xRe = (int) (xmid + wave.hWvLen); wave.pts[0].x = xLe; wave.pts[5].x = xRe; } // WaveLenSet } // WavePanel class SliderPanel extends JPanel { class AListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (ok) { // Starts if (!mStopRequest && runonce) { new WaveAnimator().start(); } else { // if (mStopRequest == false) { mStopRequest = true; runonce = true; } }//else // System.out.println("mStopRequest "+ //mStopRequest); }// if(ok) } // actionPerformed class WaveAnimator extends Thread { private WaveAnimator WA; // final double dMoveInterval = .05 ; //seconds final int mDrawInterval = 200;// milliseconds public void run() { runonce = false; while (!mStopRequest) { dp.repaint(); try { //transform() // moveWaves() Thread.sleep(mDrawInterval); } catch (InterruptedException xpt) { } } // while( mStopRequest = false; } // run } // WaveAnimator } // WavePAnel class SliderListener implements ChangeListener { public void stateChanged(ChangeEvent e) { if (e.getSource() == sliderst) { ischanged = 1; // com.bestwaveslive.wave.startval = sliderst.getValue(); } // if if (e.getSource() == sliderend) { incrflag = 1; // com.bestwaveslive.wave.endval = sliderend.getValue(); } // if } // stateChanged } // SliderListener class CustomListener implements ActionListener{ public void actionPerformed(ActionEvent evt){ rButton = (JRadioButton)evt.getSource(); if(rButton == rbdrawlines ){ dl = true ; } if(rButton == rbnotdraw ){ dl = false ; } } } SliderPanel() { GridBagLayout gridbag = new GridBagLayout(); setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(5, 5, 5, 5); JButton b_disclaimer = new JButton("DISCLAIMER"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; gridbag.setConstraints(b_disclaimer, c); add(b_disclaimer); JButton b_anim = new JButton("Go/Stop"); c.gridx = 3; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(b_anim, c); add(b_anim); b_anim.addActionListener(new AListener()); b_disclaimer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // JOptionPane.showMessageDialog(null, strung ); String choices[] = // new String[2];choices[] = { "Accept", "Reject" }; String licenseLabel = "License Agreement"; String license = "WaveBezier.java by "+ "William Redelmeier\n" + "Draws a series of breaking waves in 2 dimensions. \n "+ "Copyright (c) 2008-2010 William Redelmeier. \n "+ "This program is free software: you can redistribute it and/or \n "+ "modify it under the terms of the GNU General Public License \n "+ "as published by the Free Software Foundation, either version \n "+ "3 of the License, or (at your option) any later version. \n "+ "This program is distributed in the hope that it will be useful,\n "+ "but WITHOUT ANY WARRANTY; without even the implied warranty of \n "+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See \n "+ "the GNU General Public License for more details. \n "+ "You should have received a copy of the GNU General Public\n "+ " License along with this program. If not,\n "+ " see . \n "+ "Linking this library statically or dynamically with other\n "+ "modules is making a combined work based on this library. \n "+ "Thus, the terms and conditions of the GNU General Public License\n "+ "cover the whole combination. \n "+ "As a special exception, the copyright holders of this\n "+ "library give you permission to link this library with \n "+ "independent modules to produce an executable, regardless \n "+ "of the license terms of these independent modules, \n "+ "and to copy and distribute the resulting executable under\n "+ "terms of your choice, provided that you also meet, \n "+ "for each linked independent module, the terms and conditions\n "+ "of the license of that module. An independent module is \n "+ "a module which is not derived from or based on this library. \n "+ "If you modify this library, you may extend this exception to \n "+ "your version of the library, but you are not obligated to \n "+ "do so. If you do not wish to do so, delete this exception \n "+ "statement from your version. \n "+ "You acknowledge that the Software is not designed,\n"+ "licensed or intended for use in the design, construction, \n"+ "operation or maintenance of any nuclear facility. \n"; JScrollPane sp = new JScrollPane( new JTextArea(license, 6, 40)); Object msgs[] = new Object[] { licenseLabel, sp }; int returnValue2 = JOptionPane.CLOSED_OPTION; while (returnValue2 != 0) { // or try scroll, below returnValue2 = JOptionPane.showOptionDialog(dp, msgs, "User Agreement", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[1]); if (returnValue2 == 1) { // rejection mStopRequest = true; ok = false; // if(appletflag == true ){ // stop(); } System.exit(0); } } } }// while(r ); //.addAction // Put in private classes of sliders JLabel lFiveStart = new JLabel("CONCAVITY OF WAVE"); JLabel lFiveEnd = new JLabel("CONCAVITY OF WAVE"); c.gridx = 0; c.gridy = 1; c.gridwidth = 2; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(lFiveStart, c); add(lFiveStart); c.gridx = 3; c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; sliderst = new JSlider(JSlider.HORIZONTAL, 0, 6, 3); gridbag.setConstraints(sliderst, c); add(sliderst); sliderst.addChangeListener(new SliderListener()); c.weightx = 1.0; c.weighty = 1.0; c.gridx = 0; c.gridy = 2; c.gridwidth = 2; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(lFiveEnd, c); add(lFiveEnd); c.gridx = 3; c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; sliderend = new JSlider(JSlider.HORIZONTAL, 0, 10, 5); gridbag.setConstraints(sliderend, c); add(sliderend); sliderend.addChangeListener(new SliderListener()); rbdrawlines = new JRadioButton("with lines",false); rbdrawlines.addActionListener(new CustomListener()) ; rbnotdraw = new JRadioButton("without lines", true); rbnotdraw.addActionListener(new CustomListener()) ; ButtonGroup group = new ButtonGroup(); group.add(rbdrawlines); group.add(rbnotdraw); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; gridbag.setConstraints(rbdrawlines, c); add(rbdrawlines); c.gridx = 3; c.gridy = 3; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints(rbnotdraw, c); add(rbnotdraw); }// SliderPanel } // JPanel } // E.O.P