Hi All,
As you've probably read a million times, I am a newbie to java programming and need some help with uni assignment. I need to know how to numerical update a Textarea by clicking on a button. This would be a lot simplier if I could do it one class but my teacher wants both a Button Panel and Response Panel, which she then wants put in to a Center Panel.
I have started the code but am completey lost. Any help would be greatly appreciated.
Below are the three panel codes with a Frame code to finally put it in. I have written the driver code to run it with no problem so I wont post that. Any thing that is commented out is code that I'm not totally sure about.
public class MySurvey extends JFrame
{
private CenterPanel centerPanel;
private QuestionPanel questionPanel;
private ButtonPanel buttonPanel;
private ResponsePanel responsePanel;
public MySurvey (String header)
{
JFrame MySurvey = JFrame();
set.Title("Student Survey");
JPanel CenterPanel = new JPanel();
JPanel QuestionPanel = new JPanel();
JPanel ButtonPanel = new JPanel();
JPanel Response = new JPanel();
/*getContentPane().add(CenterPanel, BorderLayout.CENTER);
getContentPane().add(QuestionPanel, BorderLayout.SOUTH);
getContentPane().add(ButtonPanel, BorderLayout.NORTH);
getContentPane().add(ResponsePanel, BorderLayout.WEST);
*/
MySurvey.add( CenterPanel, QuestionPanel, ButtonPanel, ResponsePanel ); // add JPanels to frame
}
}//end class
Below is the center panel that joins the two panels.
public class CenterPanel extends MySurvey
{
public CenterPanel()
{
//to group ButtonPanel and ResponsePanel
CenterPanel.setLayout(new BorderLayout());
CenterPanel.add(QuestionPanel, BorderLayout.WEST);
CenterPanel.add(ResponsePanel, BorderLayout.EAST);
}
}
Below are the two Panels that go into the CenterPanel
public class ResponsePanel extends MySurvey
{
JTextField txt1 = new JTextField(5);
JTextField txt2 = new JTextField(5);
JTextField txt3 = new JTextField(5);
JTextField txt4 = new JTextField(5);
JTextField txt5 = new JTextField(5);
public void init()
{
ButtonActionListener bal = new ButtonActionListener(this);
txt1.addActionListener(bal);
txt2.addActionListener(bal);
txt3.addActionListener(bal);
txt4.addActionListener(bal);
txt5.addActionListener(bal);
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(txt1);
cp.add(txt2);
cp.add(txt3);
cp.add(txt4);
cp.add(txt5);
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ButtonPanel extends MySurvey
{
Button b1 = new Button ("BUTTON 1");
Button b2 = new Button ("BUTTON 2");
Button b3 = new Button ("BUTTON 3");
Button b4 = new Button ("BUTTON 4");
Button b5 = new Button ("BUTTON 5");
public void init()
{
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
/*ButtonActionListener bal = new ButtonActionListener(this);
b1.addActionListener(bal);
b2.addActionListener(bal);
b3.addActionListener(bal);
b4.addActionListener(bal);
b4.addActionListener(bal);
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(b1);
cp.add(b2);
cp.add(b3);
cp.add(b4);
cp.add(b5);
*/
}
//public void setButtonText (String name)
//{ txt1.setText(name); }
//for setting text are answers for buttons clicked
}
Cheers all