Problems for final year project regarding jpanel to jpanel communication

Hi, I have some problems regarding the creation of a traffic simulator using Net beans. I have three classes for a frame and two panels, namely SimUI() which is the Frame class and TunnelPanel() which extends the panel that the road and traffic will be displayed. I have got so far only to encounter some problems regarding the event listeners which are placed in SIM UI() : The frame class. I want my buttons in one panel to paint objects which re in another panel. someone PLEASE help me as I dont have much time left. Here is my code: -

import java.awt.Color;

import java.awt.Event;

import java.awt.Graphics;

import javax.swing.JSlider;

/*

* SimUI.java

*

* Created on 24 February 2007, 21:01

*/

/**

*

* @author Ben Kolosz

*/

public class SimUI extends javax.swing.JFrame {

/** Creates new form SimUI */

public SimUI() {

initComponents();

}

public class TunnelPanel extends javax.swing.JPanel {

int lineX = 0, lineY = 100;

int lineWidth = 620;

int lineHeight = 3;

int line2X = 0, line2Y = 200;

int line2Width = 620;

int line2Height = 3;

int line3X = 0, line3Y = 145;

int line3Width = 620;

int line3Height = 3;

int line4X = 0, line4Y = 155;

int line4Width = 620;

int line4Height = 3;

public void paintRoad(Graphics g) {

g.setColor(Color.black);//Paint the Tunnel road

g.fillRect(lineX, lineY, lineWidth, lineHeight);

g.fillRect(line2X, line2Y, line2Width, line2Height);

g.fillRect(line3X, line3Y, line3Width, line3Height);

g.fillRect(line4X, line4Y, line4Width, line4Height);

g.drawRect(line4X, line4Y, line4Width, line4Height);

jTextArea1.repaint();

}

public void setRequestFocusEnabled(boolean requestFocusEnabled) {

}

}

public class TrafControl extends javax.swing.JPanel {

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents() {

View = new TunnelPanel();

jScrollPane1 = new javax.swing.JScrollPane();

jTextArea1 = new javax.swing.JTextArea();

Control = new TrafControl();

TrafficFlowTBut = new javax.swing.JToggleButton();

HumanBut = new javax.swing.JButton();

AutomaticBut = new javax.swing.JButton();

ExitBut = new javax.swing.JButton();

FlowSlider = new javax.swing.JSlider();

FlowLabel = new javax.swing.JLabel();

Start = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("INTELLIGENT HIGHWAY SIMULATION v1.0");

setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

setResizable(false);

getAccessibleContext().setAccessibleName("Intelligent Highway Simulation");

View.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tunnel View", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Gill Sans Ultra Bold Condensed", 0, 11)));

View.setForeground(new java.awt.Color(224, 223, 227));

View.setOpaque(false);

jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

jTextArea1.setColumns(20);

jTextArea1.setEditable(false);

jTextArea1.setRows(1);

jTextArea1.setBorder(null);

jTextArea1.setCaretColor(new java.awt.Color(224, 223, 227));

jTextArea1.setOpaque(false);

jScrollPane1.setViewportView(jTextArea1);

jTextArea1.getAccessibleContext().setAccessibleParent(jTextArea1);

org.jdesktop.layout.GroupLayout ViewLayout = new org.jdesktop.layout.GroupLayout(View);

View.setLayout(ViewLayout);

ViewLayout.setHorizontalGroup(

ViewLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)

);

ViewLayout.setVerticalGroup(

ViewLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.TRAILING, ViewLayout.createSequentialGroup()

.addContainerGap(421, Short.MAX_VALUE)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

);

Control.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Traffic Control", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Gill Sans Ultra Bold Condensed", 0, 11), new java.awt.Color(255, 51, 51)));

TrafficFlowTBut.setLabel("Traffic Flow");

TrafficFlowTBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

HumanBut.setLabel("Human Driver Mode");

HumanBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

AutomaticBut.setLabel("Automatic Control");

AutomaticBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

ExitBut.setLabel("Exit");

ExitBut.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

ActionEvent(evt);

}

});

ExitBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

ButtonExitButBut(evt);

}

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

FlowSlider.setMajorTickSpacing(60);

FlowSlider.setMaximum(3000);

FlowSlider.setMinorTickSpacing(30);

FlowSlider.addChangeListener(new javax.swing.event.ChangeListener() {

public void stateChanged(javax.swing.event.ChangeEvent evt) {

FlowSliderStateChanged(evt);

}

});

FlowSlider.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

FlowLabel.setLabelFor(FlowSlider);

FlowLabel.setText("Vehicle Flow Rate: 0 p/h");

FlowLabel.getAccessibleContext().setAccessibleName("position");

FlowLabel.getAccessibleContext().setAccessibleDescription("position");

Start.setText("Start");

Start.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyTyped(java.awt.event.KeyEvent evt) {

StartKeyTyped(evt);

}

});

Start.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

StartMouseClicked(evt);

}

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

org.jdesktop.layout.GroupLayout ControlLayout = new org.jdesktop.layout.GroupLayout(Control);

Control.setLayout(ControlLayout);

ControlLayout.setHorizontalGroup(

ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(ControlLayout.createSequentialGroup()

.add(HumanBut)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(AutomaticBut))

.add(TrafficFlowTBut))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, ControlLayout.createSequentialGroup()

.add(6, 6, 6)

.add(Start)

.add(28, 28, 28)

.add(FlowLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(org.jdesktop.layout.GroupLayout.LEADING, ControlLayout.createSequentialGroup()

.add(10, 10, 10)

.add(ExitBut)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(FlowSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(24, Short.MAX_VALUE))

);

ControlLayout.setVerticalGroup(

ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.addContainerGap()

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(HumanBut)

.add(AutomaticBut)

.add(FlowLabel)

.add(Start))

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.add(19, 19, 19)

.add(FlowSlider, 0, 0, Short.MAX_VALUE))

.add(ControlLayout.createSequentialGroup()

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(ExitBut)

.add(TrafficFlowTBut))))

.addContainerGap())

);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, View, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(org.jdesktop.layout.GroupLayout.LEADING, Control, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(View, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(Control, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

pack();

}// </editor-fold>

private void StartMouseClicked(java.awt.event.MouseEvent evt) {

}

private void StartKeyTyped(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:

}

/**

* This method is called by the thread that was created in

* the start method. It does the main animation.

*/

private void ButtonExitButBut(java.awt.event.MouseEvent evt) {

System.exit(0);// TODO add your handling code here:

}

private void FlowSliderStateChanged(javax.swing.event.ChangeEvent evt) {

JSlider src = (JSlider) evt.getSource();

if(!src.getValueIsAdjusting())

FlowLabel.setText("Vehicle Flow Rate: "+ FlowSlider.getValue() + " p/h");

}

private void DescWipe(java.awt.event.MouseEvent evt) {

jTextArea1.setText(null);

jTextArea1.repaint();

}

private void ButtonInfo(java.awt.event.MouseEvent evt) {

if(evt.getSource() == HumanBut) jTextArea1.setText("Enables Human Reaction control variables in simulation");

if(evt.getSource() == AutomaticBut) jTextArea1.setText("Enables Automated control variables in simulation");

if(evt.getSource() == TrafficFlowTBut)jTextArea1.setText("Toggles between On/Off peak traffic conditions");

if(evt.getSource() == Start)jTextArea1.setText("Starts and stops the simulation, traffic data saved to log when stopped");

if(evt.getSource() == ExitBut)jTextArea1.setText("Exit the Program");

if(evt.getSource() == FlowSlider)jTextArea1.setText("Adjusts the amount of traffic flowing into Tunnel");

}

private void ActionEvent(java.awt.event.ActionEvent evt) {

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new SimUI().setVisible(true);

}

});

}

private String getParameter(String string) {

return null;

}

// Variables declaration - do not modify

private javax.swing.JButton AutomaticBut;

private javax.swing.JPanel Control;

private javax.swing.JButton ExitBut;

private javax.swing.JLabel FlowLabel;

private javax.swing.JSlider FlowSlider;

private javax.swing.JButton HumanBut;

private javax.swing.JButton Start;

private javax.swing.JToggleButton TrafficFlowTBut;

private javax.swing.JPanel View;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTextArea jTextArea1;

// End of variables declaration

//public declarations

private String str;

}

[14265 byte] By [Doors83a] at [2007-11-26 20:48:33]
# 1

Hi,

your not saying what you actual problem ist :O

It would be helpful if you edit yout post and and "code - /code" around your code to make sure its highlighted...

I don't see why you do things like that:

ExitBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

ButtonExitButBut(evt);

}

first, you usually add ActionListeners to buttons, your button could also be triggered with keyboard for example.

Then if you not want to handle your event inside the anonymous class, you should write an extra class handling ActionEvents... if you need acces to field of the main class it would be an good Idea to have your main class implement ActionListener and then simply write a method actionPerformed(ActionEvent aE) { ...}. Then you could decide on eA.getActionCommand(); what to do. getActionCommand() returns a String which is usaully equal to your button text... ouf course you could also compare the source like you did...

-jEti

jEti182a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 2
hmm are some of those methods stubs you have to use?because of the "// TODO add your handling code here:"'s.or generateds by some gui-creation-tool? you should definatly format you code!
jEti182a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi we are in a different timezone to you so sorry I didnt reply Ive been asleep, how do you highlight your code like that? code (place code here) -/code<=is that it.

I already have a mouselistener event called mouse clicked, what I cannot do is link the button related to the SIMUI() frame class where the event listner is to the jpanel in the TunnelPanel() class so that it paints in Tunnel Panel.

In other words how do you link a Jbutton eventlistner in one panel to another class containing a different jpanel. Do you need to call a method iinstance of the class that draws the object to the screen?

Doors83a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 4

for highlighting cyou add "code" before end "/code" behind your code, each in bracets: http://forum.java.sun.com/help.jspa?sec=formatting ..

for your problem:

does it not work giving the inner classes (TunnelPane etc.) public methods that can be called from the eventlistenener? i have no time now to read your code completely ... i do not see where your panel classes get instanziated...

I assume you would add them to a JFrame or some other container ...

in a way like that :

TunnelPanel() tp = new TunnelPanel();

SIMUI().add(tp);

and in your listener simply call tp.yourPublicMethod(your paramters)....

maybe i can help you tommorow by actually running your code ... if its not solved then...

-jEti

jEti182a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 5

View = new TunnelPanel();

This is my panel instance which I have placed at the start of the generated code that Netbeans uses. I had to actually create custom code for this to be displayed but anyhoo I already tried that. The methodI want to call is

public void paintRoad(Graphics g)

I have already attempted to call the method from the mouseclick event listener in SIM UI:

TunnelPanel.paintRoad(Graphics g)

but a compiler error reads cannot issue a static command or something like that: -

Here is my code formatted, hope you can help mate.:)

import java.awt.Color;

import java.awt.Event;

import java.awt.Graphics;

import javax.swing.JSlider;

/*

* SimUI.java

*

* Created on 24 February 2007, 21:01

*/

/**

*

* @author Ben Kolosz

*/

public class SimUI extends javax.swing.JFrame {

/** Creates new form SimUI */

public SimUI() {

initComponents();

}

public class TunnelPanel extends javax.swing.JPanel {

int lineX = 0, lineY = 100;

int lineWidth = 620;

int lineHeight = 3;

int line2X = 0, line2Y = 200;

int line2Width = 620;

int line2Height = 3;

int line3X = 0, line3Y = 145;

int line3Width = 620;

int line3Height = 3;

int line4X = 0, line4Y = 155;

int line4Width = 620;

int line4Height = 3;

public void paintRoad(Graphics g) {

g.setColor(Color.black); //Paint the Tunnel road

g.fillRect(lineX, lineY, lineWidth, lineHeight);

g.fillRect(line2X, line2Y, line2Width, line2Height);

g.fillRect(line3X, line3Y, line3Width, line3Height);

g.fillRect(line4X, line4Y, line4Width, line4Height);

g.drawRect(line4X, line4Y, line4Width, line4Height);

jTextArea1.repaint();

}

public void setRequestFocusEnabled(boolean requestFocusEnabled) {

}

}

public class TrafControl extends javax.swing.JPanel {

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents() {

View = new TunnelPanel();

jScrollPane1 = new javax.swing.JScrollPane();

jTextArea1 = new javax.swing.JTextArea();

Control = new TrafControl();

TrafficFlowTBut = new javax.swing.JToggleButton();

HumanBut = new javax.swing.JButton();

AutomaticBut = new javax.swing.JButton();

ExitBut = new javax.swing.JButton();

FlowSlider = new javax.swing.JSlider();

FlowLabel = new javax.swing.JLabel();

Start = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("INTELLIGENT HIGHWAY SIMULATION v1.0");

setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

setResizable(false);

getAccessibleContext().setAccessibleName("Intelligent Highway Simulation");

View.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tunnel View", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Gill Sans Ultra Bold Condensed", 0, 11)));

View.setForeground(new java.awt.Color(224, 223, 227));

View.setOpaque(false);

jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

jTextArea1.setColumns(20);

jTextArea1.setEditable(false);

jTextArea1.setRows(1);

jTextArea1.setBorder(null);

jTextArea1.setCaretColor(new java.awt.Color(224, 223, 227));

jTextArea1.setOpaque(false);

jScrollPane1.setViewportView(jTextArea1);

jTextArea1.getAccessibleContext().setAccessibleParent(jTextArea1);

org.jdesktop.layout.GroupLayout ViewLayout = new org.jdesktop.layout.GroupLayout(View);

View.setLayout(ViewLayout);

ViewLayout.setHorizontalGroup(

ViewLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)

);

ViewLayout.setVerticalGroup(

ViewLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(org.jdesktop.layout.GroupLayout.TRAILING, ViewLayout.createSequentialGroup()

.addContainerGap(421, Short.MAX_VALUE)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

);

Control.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Traffic Control", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Gill Sans Ultra Bold Condensed", 0, 11), new java.awt.Color(255, 51, 51)));

TrafficFlowTBut.setLabel("Traffic Flow");

TrafficFlowTBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

HumanBut.setLabel("Human Driver Mode");

HumanBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

AutomaticBut.setLabel("Automatic Control");

AutomaticBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

ExitBut.setLabel("Exit");

ExitBut.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

ActionEvent(evt);

}

});

ExitBut.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

ButtonExitButBut(evt);

}

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

FlowSlider.setMajorTickSpacing(60);

FlowSlider.setMaximum(3000);

FlowSlider.setMinorTickSpacing(30);

FlowSlider.addChangeListener(new javax.swing.event.ChangeListener() {

public void stateChanged(javax.swing.event.ChangeEvent evt) {

FlowSliderStateChanged(evt);

}

});

FlowSlider.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

FlowLabel.setLabelFor(FlowSlider);

FlowLabel.setText("Vehicle Flow Rate: 0 p/h");

FlowLabel.getAccessibleContext().setAccessibleName("position");

FlowLabel.getAccessibleContext().setAccessibleDescription("position");

Start.setText("Start");

Start.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyTyped(java.awt.event.KeyEvent evt) {

StartKeyTyped(evt);

}

});

Start.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

StartMouseClicked(evt);

}

public void mouseEntered(java.awt.event.MouseEvent evt) {

ButtonInfo(evt);

}

public void mouseExited(java.awt.event.MouseEvent evt) {

DescWipe(evt);

}

});

org.jdesktop.layout.GroupLayout ControlLayout = new org.jdesktop.layout.GroupLayout(Control);

Control.setLayout(ControlLayout);

ControlLayout.setHorizontalGroup(

ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(ControlLayout.createSequentialGroup()

.add(HumanBut)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(AutomaticBut))

.add(TrafficFlowTBut))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, ControlLayout.createSequentialGroup()

.add(6, 6, 6)

.add(Start)

.add(28, 28, 28)

.add(FlowLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(org.jdesktop.layout.GroupLayout.LEADING, ControlLayout.createSequentialGroup()

.add(10, 10, 10)

.add(ExitBut)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(FlowSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(24, Short.MAX_VALUE))

);

ControlLayout.setVerticalGroup(

ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.addContainerGap()

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(HumanBut)

.add(AutomaticBut)

.add(FlowLabel)

.add(Start))

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(ControlLayout.createSequentialGroup()

.add(19, 19, 19)

.add(FlowSlider, 0, 0, Short.MAX_VALUE))

.add(ControlLayout.createSequentialGroup()

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(ControlLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)

.add(ExitBut)

.add(TrafficFlowTBut))))

.addContainerGap())

);

org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)

.add(org.jdesktop.layout.GroupLayout.LEADING, View, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.add(org.jdesktop.layout.GroupLayout.LEADING, Control, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(View, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(Control, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

pack();

}// </editor-fold>

private void StartMouseClicked(java.awt.event.MouseEvent evt) {

}

private void StartKeyTyped(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:

}

/**

* This method is called by the thread that was created in

* the start method. It does the main animation.

*/

private void ButtonExitButBut(java.awt.event.MouseEvent evt) {

System.exit(0);// TODO add your handling code here:

}

private void FlowSliderStateChanged(javax.swing.event.ChangeEvent evt) {

JSlider src = (JSlider) evt.getSource();

if(!src.getValueIsAdjusting())

FlowLabel.setText("Vehicle Flow Rate: "+ FlowSlider.getValue() + " p/h");

}

private void DescWipe(java.awt.event.MouseEvent evt) {

jTextArea1.setText(null);

jTextArea1.repaint();

}

private void ButtonInfo(java.awt.event.MouseEvent evt) {

if(evt.getSource() == HumanBut) jTextArea1.setText("Enables Human Reaction control variables in simulation");

if(evt.getSource() == AutomaticBut) jTextArea1.setText("Enables Automated control variables in simulation");

if(evt.getSource() == TrafficFlowTBut)jTextArea1.setText("Toggles between On/Off peak traffic conditions");

if(evt.getSource() == Start)jTextArea1.setText("Starts and stops the simulation, traffic data saved to log when stopped");

if(evt.getSource() == ExitBut)jTextArea1.setText("Exit the Program");

if(evt.getSource() == FlowSlider)jTextArea1.setText("Adjusts the amount of traffic flowing into Tunnel");

}

private void ActionEvent(java.awt.event.ActionEvent evt) {

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new SimUI().setVisible(true);

}

});

}

private String getParameter(String string) {

return null;

}

// Variables declaration - do not modify

private javax.swing.JButton AutomaticBut;

private javax.swing.JPanel Control;

private javax.swing.JButton ExitBut;

private javax.swing.JLabel FlowLabel;

private javax.swing.JSlider FlowSlider;

private javax.swing.JButton HumanBut;

private javax.swing.JButton Start;

private javax.swing.JToggleButton TrafficFlowTBut;

private javax.swing.JPanel View;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTextArea jTextArea1;

// End of variables declaration

//public declarations

private String str;

}

Doors83a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 6
Apparently if it helps when I try to get my event listener to point to the paint method in the TunnelPanel class then it says that paint road in SimUI.TunnelPanel cannot be applied to () ?
Doors83a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...
# 7

Hmm i cant try oyu code here... cannot resolve all the layout stuff.

that might come from netbeans stuff which i never worked with and is not installed here.

this "static" relatet error usually occurs if youre trying to call static class method from a dynamic context.

like this:

class A{

static public void doSomething()

{ //dosomething }

}

class B {

A x= new A();

x.doSomething(); // Would cause that error because x is an object your calling the method od

A.doSomethin(); // would work!

}

Im not sure if that your problem... but check if your doing something like taht somewhere...

It also might be possible that the problem depends on using inner Classes..

Im not sure about that either ...i almost never use inner classes!

Try to use only outer classes:

Class A { ...}

Class B {...}

instead of

Class A{

Class B{....}

}

maybe ti will work then or atleast help you to see whats going wrong

also try to keep fields and methods (if only used internal) private

and create public getYourVariable() and seYourVariable(value) methods to have access from outside.

hope that helps a little...

-jAn

Message was edited by:

jEti182

jEti182a at 2007-7-10 2:11:49 > top of Java-index,Desktop,Core GUI APIs...