13. april 2005 - 15:36
Der er
15 kommentarer og 2 løsninger
paint metode
Hej! Jeg har skrevet det her : public void paint(Graphics g){ g.drawLine(100,250,200,250); } Og det virker faktisk også som det skal, men den metode blir kaldt lige så snart jeg starter det hele og det var ikk meninngen ... Det først når jeg trykker på min knap den ska tegne det ... Og noget helt andet er at, de ting som også er i min frame, dem kan man ikk se, kun hvis jeg trykker på dem fordi jeg ved de er der dykker de frem ... Nogle som kan hjælpe med de 2 problemer :) // rosgaard
Annonceindlæg fra Infor
13. april 2005 - 16:06
#6
package bikecpu; import java.awt.*; import javax.swing.*; import com.borland.jbcl.layout.XYLayout; import com.borland.jbcl.layout.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */ public class TrackEditor extends JFrame { JLabel jLabel1 = new JLabel(); XYLayout TrackEditor = new XYLayout(); JButton BackButton = new JButton(); bikeapp ba; JSlider slider1 = new JSlider(1, 7, 1); JSlider slider2 = new JSlider(1, 7, 1); JSlider slider3 = new JSlider(1, 7, 1); JSlider slider4 = new JSlider(1, 7, 1); JButton CreateTrackButton = new JButton(); JFormattedTextField GearTextField1 = new JFormattedTextField(); JFormattedTextField GearTextField2 = new JFormattedTextField(); JFormattedTextField GearTextField3 = new JFormattedTextField(); JFormattedTextField GearTextField4 = new JFormattedTextField(); //private Graphics g; public TrackEditor() { try { jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } private void jbInit() throws Exception { getContentPane().setLayout(TrackEditor); jLabel1.setFont(new java.awt.Font("Trebuchet MS", Font.PLAIN, 33)); jLabel1.setText("TRACK EDITORRRR !\"#!\"#"); CreateTrackButton.setText("Create Track"); CreateTrackButton.addActionListener(new TrackEditor_CreateTrackButton_actionAdapter(this)); BackButton.addActionListener(new TrackEditor_BackButton_actionAdapter(this)); TrackEditor.setWidth(720); TrackEditor.setHeight(531); GearTextField1.setEditable(false); GearTextField1.setText(""); GearTextField2.setEditable(false); GearTextField2.setText(""); GearTextField3.setEditable(false); GearTextField3.setText(""); GearTextField4.setEditable(false); GearTextField4.setText(""); slider4.addChangeListener(new TrackEditor_changeAdapter(this)); slider3.addChangeListener(new TrackEditor_changeAdapter(this)); slider2.addChangeListener(new TrackEditor_changeAdapter(this)); slider1.addChangeListener(new TrackEditor_changeAdapter(this)); this.getContentPane().add(jLabel1, new XYConstraints(66, 21, 550, 47)); this.getContentPane().add(slider1, new XYConstraints(25, 340, 70, 80)); this.getContentPane().add(slider2, new XYConstraints(100, 340, 70, 80)); this.getContentPane().add(slider3, new XYConstraints(175, 340, 70, 80)); this.getContentPane().add(slider4, new XYConstraints(250, 340, 70, 80)); this.getContentPane().add(BackButton, new XYConstraints(528, 446, 110, 40)); this.getContentPane().add(GearTextField1, new XYConstraints(25, 295, 65, 35)); this.getContentPane().add(GearTextField2, new XYConstraints(100, 295, 65, 35)); this.getContentPane().add(GearTextField3, new XYConstraints(175, 295, 65, 35)); this.getContentPane().add(GearTextField4, new XYConstraints(250, 295, 65, 35)); this.getContentPane().add(CreateTrackButton, new XYConstraints(18, 459, 110, 40)); BackButton.setText("Back"); CreateTrackButton.setMargin(new Insets(2, 7, 2, 7)); slider1.setOrientation(JSlider.VERTICAL); slider2.setOrientation(JSlider.VERTICAL); slider3.setOrientation(JSlider.VERTICAL); slider4.setOrientation(JSlider.VERTICAL); slider1.setPaintTicks(true); slider2.setPaintTicks(true); slider3.setPaintTicks(true); slider4.setPaintTicks(true); slider1.setMajorTickSpacing(6); slider1.setMinorTickSpacing(1); slider2.setMajorTickSpacing(6); slider2.setMinorTickSpacing(1); slider3.setMajorTickSpacing(6); slider3.setMinorTickSpacing(1); slider4.setMajorTickSpacing(6); slider4.setMinorTickSpacing(1); GearTextField1.setText("Gear: "+String.valueOf(slider1.getValue())); GearTextField2.setText("Gear: "+String.valueOf(slider2.getValue())); GearTextField3.setText("Gear: "+String.valueOf(slider3.getValue())); GearTextField4.setText("Gear: "+String.valueOf(slider4.getValue())); } public void paint(Graphics g){ super.paint(g); g.drawLine(100,250,200,250); } public void CreateTrackButton_actionPerformed(ActionEvent e) { //paint1(g); System.out.println("Hej"); } public void BackButton_actionPerformed(ActionEvent e) { MainMenuFrame MMF = new MainMenuFrame(); MMF.setSize(400, 400); MMF.setTitle("Main Menu"); MMF.pack(); MMF.setVisible(true); MMF.UserLabel.setText(ba.CurUser); dispose(); CenterClass.centerClass(MMF); } // Register a change listener // This method is called whenever the slider's value is changed public void stateChanged(ChangeEvent e) { GearTextField1.setText("Gear: "+String.valueOf(slider1.getValue())); GearTextField2.setText("Gear: "+String.valueOf(slider2.getValue())); GearTextField3.setText("Gear: "+String.valueOf(slider3.getValue())); GearTextField4.setText("Gear: "+String.valueOf(slider4.getValue())); } } class TrackEditor_changeAdapter implements ChangeListener { private TrackEditor adaptee; TrackEditor_changeAdapter(TrackEditor adaptee) { this.adaptee = adaptee; } public void stateChanged(ChangeEvent e) { adaptee.stateChanged(e); } } class TrackEditor_CreateTrackButton_actionAdapter implements ActionListener { private TrackEditor adaptee; TrackEditor_CreateTrackButton_actionAdapter(TrackEditor adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.CreateTrackButton_actionPerformed(e); } } class TrackEditor_BackButton_actionAdapter implements ActionListener { private TrackEditor adaptee; TrackEditor_BackButton_actionAdapter(TrackEditor adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.BackButton_actionPerformed(e); } }