![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: help me |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] Jslider Hey is there any one who can help with this I have to plot sliderbar that h as 3 pointers on bar for the 3 grades a,b,c on a scale of 100 for the class On the left side of it i need to have the name of the students with rectangular projection of the grade( like if a student got 85 % his individual rectangular bar must be upto 83 % level of the slider bar etc ) these 3 pointers for a, b ,c grade must be movable like i can adjust my own values for the grades on the same slider i need help i need to complete this by mondayplease help me |
| |
| |||
| import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class SliderFrame extends JFrame { public static JSlider diameterJSlider; // slider to select diameter // panel to draw circle // no-argument constructor public SliderFrame() { super ( "Student chart" ); add(new Test()); add(new Test2()); setLayout(new BorderLayout()); JLabel n = new JLabel("true"); JLabel n1 = new JLabel("true1"); n.setForeground( Color.red); JPanel j = new JPanel(); JPanel j2 = new JPanel(); j.setLayout( new GridLayout(3,0)); //j.add(new JLabel("neeee")); j2.setLayout( new GridLayout(3,0)); j2.add(new JLabel("namessssss")); j2.add(n); j2.add(new JLabel("mary")); j.add(new Test()); j.add(new Test()); j.add(new Test()); add(j2,BorderLayout.WEST); add(j,BorderLayout.CENTER); // set up JSlider to control diameter value diameterJSlider = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 ); JSlider diameterJSlider1 = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 ); diameterJSlider1.setForeground(Color.BLUE); diameterJSlider1.setMajorTickSpacing( 20 ); // create tick every 10 diameterJSlider1.setPaintTicks( true ); // paint ticks on slider diameterJSlider1.setPaintLabels(true); diameterJSlider.setMajorTickSpacing( 10 ); // create tick every 10 diameterJSlider.setPaintTicks( true ); // paint ticks on slider diameterJSlider.setPaintLabels(true); diameterJSlider.add(new NewPanel()); JSlider diameterJSlider3 = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 ); JSlider diameterJSlider4 = new JSlider( SwingConstants.HORIZONTAL, 0, 100, 0 ); diameterJSlider3.setMajorTickSpacing( 20 ); // create tick every 10 diameterJSlider3.setPaintTicks( true ); // paint ticks on slider diameterJSlider3.setPaintLabels(true); diameterJSlider4.setMajorTickSpacing( 10 ); // create tick every 10 diameterJSlider4.setPaintTicks( true ); // paint ticks on slider diameterJSlider4.setPaintLabels(true); diameterJSlider4.add(new NewPanel()); diameterJSlider4.setForeground(Color.red); diameterJSlider3.setForeground(Color.ORANGE); diameterJSlider.setForeground(Color.CYAN); diameterJSlider.add("aaa",new JLabel("a")); diameterJSlider.addChangeListener( new ChangeListener() // anonymous inner class { // handle change in slider value public void stateChanged( ChangeEvent e ) { //myPanel.setDiameter( diameterJSlider.getValue() ); } // end method stateChanged } // end anonymous inner class ); JPanel j3 = new JPanel(); j3.setLayout(new GridLayout(2,2)); JLabel a = new JLabel(" A grade"); JLabel b = new JLabel(" B grade"); j3.add(a); j3.add(diameterJSlider); j3.add(b); j3.add(diameterJSlider1); add( j3,BorderLayout.SOUTH); JPanel j4 = new JPanel(); add( j4,BorderLayout.NORTH); j4.setLayout(new GridLayout(2,2,0,0)); JLabel c = new JLabel(" D grade"); JLabel d = new JLabel(" C grade"); j4.add(c); j4.add(diameterJSlider3); j4.add(d); j4.add(diameterJSlider4); // add( diameterJSlider1,BorderLayout.NORTH); // j2.add(diameterJSlider); } // end SliderFrame constructor public static void main( String args[] ) { SliderFrame sliderFrame = new SliderFrame(); sliderFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); sliderFrame.setSize( 800, 270 ); // set frame size sliderFrame.setVisible( true ); // display frame } // class NewPanel extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawLine(0, 0, 50, 50); g.drawRect(0, 0, 100, 10); } } // } import java.awt.Color; import java.awt.Graphics; import java.awt.*; import javax.swing.*; public class Test extends JPanel { publicvoid paintComponent(Graphics g) { super.paintComponent(g); boolean color=true; g.setColor(Color.black); g.setColor(Color.green); g.fillRect(SliderFrame.diameterJSlider.get ), SliderFrame.diameterJSlider.getY()+100, 200, 10);// g.fillRect(200, 70, 200, 10); g.fillOval(400, 70, 10,10); // g.fillRect(SliderFrame.diameterJSlider.get ), SliderFrame.diameterJSlider.get ), 5, 50);} } This is the code that i have somebody could please help me out with this I thought that this is the site where you can disscuss ur stuff nad not pay |
| |||
| No i store everything in arrays and in the form of files. but if you can help me with this where i just need to connect the pointer ofthe slider with a single line tha moves across the screen with the movement of the slider pointer that would be a help. I just need to make that work. Rest i have working |
| ||||
| I haven't personally tested your code since I'm now very busy with final exam tomorrow lol... But I'd suggest to use this to set the current value of the slider: Code: void setValue(int n)
Sets the sliders current value. Let me know if it works and the problem that you're encountering... Sorry, I can't help much now but by just giving you abstract implementation.. hope that helps you ![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |