How to add working JScrollPane to JTextArea? - jscrollpane

I have a problem with this code. At " //Jūsu piedāvātais preču sortiments" I'm trying to add JScrollPane into JTextArea. I have tried lots for methods, but no one of them works. Only thing what I can do is to add it but it will not work what ever I do. So, if someone have any idea how to do it, it would be greatly appreciate.
Here is the code:
import java.awt.*;
import javax.swing.*;
public class otraForma {
public static void main(String[] args) {
JFrame frame = new JFrame("Pieteikuma forma");
frame.setSize(new Dimension(355, 500));
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
komponenti(panel);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void komponenti(JPanel panel) {
panel.setLayout(null);
/*Šeit uzskaita visu formu
* Tai skaitaa ari izmerus. Tos droši vien jāliek, lai autmātiski maina,
* bet nezinu kā to izdarīt. Vēlāk arī pievinos krāsas vai dizainu.
*/
//------------JTextField-------------//
//Vārds
JLabel vards = new JLabel("Vārds"); //ar JLabel izveido pāsu textu
vards.setBounds(10, 10, 80, 25); //ievieto mērogu (tas būs jāmaina)
panel.add(vards); //pievieno viņu formai
JTextField vards_texts = new JTextField(20); //tiek izveidots ievades laukums
vards_texts.setBounds(100, 10, 240, 25);
panel.add(vards_texts);
//------------JTextField-------------//
//Uzvārds
JLabel uzvards = new JLabel("Uzvārds");
uzvards.setBounds(10, 40, 80, 25);
panel.add(uzvards);
JTextField uzvars_texts = new JTextField(20);
uzvars_texts.setBounds(100, 40, 240, 25);
panel.add(uzvars_texts);
//------------JTextField-------------//
//E-pasts
JLabel epasts = new JLabel("E-pasts");
epasts.setBounds(10, 70, 80, 25);
panel.add(epasts);
JTextField epasts_texts = new JTextField(30);
epasts_texts.setBounds(100, 70, 240, 25);
panel.add(epasts_texts);
//------------JComboBox-------------//
//Vēlamais apmeklējuma datums
JLabel datums = new JLabel("Apmeklējums");
datums.setBounds(10, 100, 80, 25);
panel.add(datums);
JComboBox datums_drop_menesi = new JComboBox();
datums_drop_menesi.addItem("Janvāris");
datums_drop_menesi.addItem("Februāris");
datums_drop_menesi.addItem("Marts");
datums_drop_menesi.addItem("Aprīlis");
datums_drop_menesi.addItem("Maijs");
datums_drop_menesi.addItem("Jūnis");
datums_drop_menesi.addItem("Jūlijs");
datums_drop_menesi.addItem("Augusts");
datums_drop_menesi.addItem("Septembris");
datums_drop_menesi.addItem("Oktobris");
datums_drop_menesi.addItem("Novembris");
datums_drop_menesi.addItem("Decembris");
//datums_drop_menesi.setMaximumRowCount(datums_drop_menesi.getModel().getSize());
datums_drop_menesi.setBounds(100, 100, 115, 25); //(* , *, garums, *)
panel.add(datums_drop_menesi);
JComboBox datums_drop_dienas = new JComboBox();
for(int i=1;i<=31;i++) {
datums_drop_dienas.addItem(new Integer(i));
}
datums_drop_dienas.setBounds(225, 100, 115, 25);
panel.add(datums_drop_dienas);
//------------JCheckBox-------------//
//Vai nepieciešams pavilijons?
JLabel pavilijons = new JLabel("Vai nepieciešams pavilijons?");
pavilijons.setBounds(10, 130, 170, 25);
panel.add(pavilijons);
JCheckBox pavilijons_check1 = new JCheckBox();
pavilijons_check1.setText("Jā");
pavilijons_check1.setBounds(225, 130, 40, 25);
panel.add(pavilijons_check1);
JCheckBox pavilijons_check2 = new JCheckBox();
pavilijons_check2.setText("Nē");
pavilijons_check2.setBounds(300, 130, 40, 25);
panel.add(pavilijons_check2);
ButtonGroup group1 = new ButtonGroup(); //nodrošina to, ka tikai, ka viens check box
group1.add(pavilijons_check1); //ir nospiests vienlaiciigi
group1.add(pavilijons_check2);
//------------JCheckBox-------------//
//Vai nepieciešams tirgus galds?
JLabel galds = new JLabel("Vai nepieciešams tirgus galds?");
galds.setBounds(10, 160, 180, 25);
panel.add(galds);
JCheckBox galds_check1 = new JCheckBox();
galds_check1.setText("Jā");
galds_check1.setBounds(225, 160, 40, 25);
panel.add(galds_check1);
JCheckBox galds_check2 = new JCheckBox();
galds_check2.setText("Nē");
galds_check2.setBounds(300, 160, 40, 25);
panel.add(galds_check2);
ButtonGroup group2 = new ButtonGroup();
group2.add(galds_check1);
group2.add(galds_check2);
//------------JCheckBox-------------//
//Vai nepieciešams elektrības pieslēgums?
JLabel elektriba = new JLabel("Vai nepieciešama elektrība?");
elektriba.setBounds(10, 190, 180, 25);
panel.add(elektriba);
JCheckBox elektriba_check1 = new JCheckBox();
elektriba_check1.setText("Jā");
elektriba_check1.setBounds(225, 190, 40, 25);
panel.add(elektriba_check1);
JCheckBox elektriba_check2 = new JCheckBox();
elektriba_check2.setText("Nē");
elektriba_check2.setBounds(300, 190, 40, 25);
ButtonGroup group3 = new ButtonGroup();
group3.add(elektriba_check1);
group3.add(elektriba_check2);
panel.add(elektriba_check2);
//------------JTextField-------------//
//Jūsu piedāvātais preču sortiments
JLabel piedavajums = new JLabel("Jūsu piedāvātais preču sortiments.");
piedavajums.setBounds(10, 220, 325, 25);
panel.add(piedavajums);
JTextArea piedavajums_texts = new JTextArea();
piedavajums_texts.setBounds(10, 250, 300, 100);
piedavajums_texts.setWrapStyleWord(true);
piedavajums_texts.setLineWrap(true);
JScrollPane sp = new JScrollPane(piedavajums_texts);
sp.getVerticalScrollBar();
sp.setBounds(300, 250, 20, 100);
panel.add(sp);
panel.add(piedavajums_texts);
//------------JButton-------------//
//Beigt
JButton atpakal = new JButton("Info");
atpakal.setBounds(10, 425, 80, 25); // x-ass, y-ass. texkta bloka garums/augstums
panel.add(atpakal);
//Importēt
JButton imports = new JButton("Importēt");
imports.setBounds(123, 425, 100, 25);
panel.add(imports);
//Beigt
JButton beigt = new JButton("Beigt");
beigt.setBounds(255, 425, 80, 25);
panel.add(beigt);
}
}

Related

how to make shorter hard coded Jframe?

I'm just a beginner in coding. and we're using Net-beans.
here is the sample output he is expecting or want us to code.
sample output
Our prof. wants us to create a program without using any short-cut or other class(1 class and 1 main method). here is my codes and i want to make it short. is there a possible way?
package chuajframe;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ChuaJFrame {
static double price;
static double subTotal = 0;
static double subTotal1 = 0;
static int qty;
static double total = 0;
static double change;
static double bill;
public static void main(String s[]) {
JFrame z = new JFrame("Chua JFrame");
JLabel label = new JLabel("Welcome");
label.setBounds(160, 0, 100, 20);
JLabel a = new JLabel("Descrition Price
Quantity"); a.setBounds(10, 10, 400, 50);
//JLabel a1 = new JLabel("Price"); a1.setBounds(120,10,100, 50);
//JLabel a2 = new JLabel("Quantity"); a2.setBounds(210,10,100, 50);
JTextField b = new JTextField(); b.setBounds(10,50, 70, 20);
JTextField b1= new JTextField(); b1.setBounds(120,50, 70, 20);
JTextField b2= new JTextField(); b2.setBounds(210,50, 70, 20);
JButton b3 = new JButton("Add"); b3.setBounds(300,50,70, 20);
JTextField c = new JTextField(); c.setBounds(10,80, 70, 20);
JTextField c1= new JTextField(); c1.setBounds(120,80, 70, 20);
JTextField c2= new JTextField(); c2.setBounds(210,80, 70, 20);
JButton c3 = new JButton("Add"); c3.setBounds(300,80,70, 20);
JLabel label1 = new JLabel("Your about to purchase the following");label1.setBounds(90, 100, 300,30);
JLabel label2 = new JLabel("Subtotal"); label2.setBounds(280, 120, 300,30);
JLabel d = new JLabel(); d.setBounds(10, 150, 100, 20);
JLabel d1 = new JLabel(); d1.setBounds(120,150,100, 20);
JLabel d2 = new JLabel(); d2.setBounds(210,150,100, 20);
JLabel d3 = new JLabel(); d3.setBounds(300,150,100, 20);
JLabel e = new JLabel(); e.setBounds(10, 180, 100, 20);
JLabel e1 = new JLabel(); e1.setBounds(120,180,100, 20);
JLabel e2 = new JLabel(); e2.setBounds(210,180,100, 20);
JLabel e3 = new JLabel(); e3.setBounds(300,180,100, 20);
JLabel f = new JLabel("Total"); f.setBounds(210, 210, 100, 20);
JLabel f1 = new JLabel(); f1.setBounds(300, 210, 100, 20);
JTextField g = new JTextField(); g.setBounds(250,240,100,20);
JButton g1 = new JButton("Payment"); g1.setBounds(140,240,100, 20);
JLabel h = new JLabel(); h.setBounds(140,270,200, 20);
JLabel h1 = new JLabel(); h1.setBounds(300,270,80, 20);
JLabel i = new JLabel(); i.setBounds(140,285,200, 20);
b3.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent e){
d.setText(b.getText());
d1.setText(b1.getText());
d2.setText(b2.getText());
price = Double.parseDouble(d1.getText());
qty = Integer.parseInt(d2.getText());
subTotal = price * qty;
d3.setText(Double.toString(subTotal));
total = subTotal + subTotal1;
f1.setText(Double.toString(total));
b.setText(" ");
b1.setText(" ");
b2.setText(" ");
}});
c3.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent ae){
e.setText(c.getText());
e1.setText(c1.getText());
e2.setText(c2.getText());
price = Double.parseDouble(e1.getText());
qty = Integer.parseInt(e2.getText());
subTotal1 = price * qty;
e3.setText(Double.toString(subTotal1));
total = subTotal + subTotal1;
f1.setText(Double.toString(total));
c.setText(" ");
c1.setText(" ");
c2.setText(" ");
}});
g1.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent e){
bill = Double.parseDouble(g.getText());
if(bill>total)
{
change = bill - total;
h.setText("Change");
h1.setText(Double.toString(change));
i.setText("Thank you for purchasing.");
}
else{
h.setText("Sorry insufficient payment.");
i.setText("Please enter your payment again!!");
}
}});
z.add(label);
z.add(a); //z.add(a1); z.add(a2);
z.add(b); z.add(b1); z.add(b2); z.add(b3);
z.add(c); z.add(c1); z.add(c2); z.add(c3);
z.add(label1); z.add(label2);
z.add(d); z.add(d1); z.add(d2); z.add(d3);
z.add(e); z.add(e1); z.add(e2); z.add(e3);
z.add(f); z.add(f1);
z.add(g); z.add(g1);
z.add(h); z.add(h1);
z.add(i);
z.setSize(400,350);
z.setLayout(null);
z.setVisible(true);
z.setLocationRelativeTo(null);
z.setResizable(false);
z.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
You can do something called compound instantiation with most of your fields.
For example, turn this:
static double price;
static double subTotal = 0;
static double subTotal1 = 0;
static int qty;
static double total = 0;
static double change;
static double bill;
Into this:
static double price = 0, subTotal = 0, subTotal1 = 0, total = 0, change = 0, bill = 0;
static int qty;
Or this:
JTextField b = new JTextField();
JTextField b1= new JTextField();
JTextField b2= new JTextField();
JButton b3 = new JButton("Add");
Into this:
JTextField b = new JTextField(), b1= new JTextField(), b2= new JTextField(), b3 = new JButton("Add");
And then use a for loop to add all the things to z that you need to add at the bottom of your class

How to pan/scale the contents inside a GUI area?

I want to have a zoom effect inside an area in a EditorWindow, something like a zoomable scrollview.
The following snippet deals only with the panning effect but it exemplifies the issue I'm having when the contents inside the zoomable area and the clipping rect can't be handled independently of each other through hSliderValue1 (clipping) and hSliderValue2 (panning).
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ZoomTestWindow : EditorWindow
{
private static float kEditorWindowTabHeight = 20;
private static Matrix4x4 _prevGuiMatrix;
public static float hSliderValue1 = 0;
public static float hSliderValue2 = 0;
Rect[] wr = new Rect[]{
new Rect(0, 0, 100, 100),
new Rect(50, 50, 100, 100),
new Rect(100, 100, 100, 100)
};
[MenuItem("Window/Zoom Test #%w")]
private static void Init()
{
ZoomTestWindow window = EditorWindow.GetWindow<ZoomTestWindow>("Zoom Test", true, new System.Type[] {
typeof(UnityEditor.SceneView),
typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow")});
window.Show();
EditorWindow.FocusWindowIfItsOpen<ZoomTestWindow>();
}
public static Rect BeginZoomArea()
{
GUI.EndGroup(); //End the group that Unity began so we're not bound by the EditorWindow
GUI.BeginGroup(new Rect(hSliderValue1, 0, 200, 200));
_prevGuiMatrix = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(new Vector2(hSliderValue2, 0), Quaternion.identity, Vector3.one);;
return new Rect();
}
public static void EndZoomArea()
{
GUI.matrix = _prevGuiMatrix;
GUI.EndGroup();
GUI.BeginGroup(new Rect(0.0f, kEditorWindowTabHeight, Screen.width, Screen.height - (kEditorWindowTabHeight + 3)));
}
public void OnGUI()
{
BeginZoomArea();
BeginWindows();
wr[0] = GUI.Window(0, wr[0], DrawWindow, "hello");
wr[1] = GUI.Window(1, wr[1], DrawWindow, "world");
wr[2] = GUI.Window(2, wr[2], DrawWindow, "!");
EndWindows();
EndZoomArea();
hSliderValue1 = GUI.HorizontalSlider(new Rect(200, 5, 100, 30), hSliderValue1, 0, 100);
hSliderValue2 = GUI.HorizontalSlider(new Rect(200, 25, 100, 30), hSliderValue2, 0, 100);
}
void DrawWindow(int id)
{
GUI.Button(new Rect(0, 30, 100, 50), "Wee!");
GUI.DragWindow();
}
}
Is there a way to do this, maybe by using a scroll view?
Embed the group controlled by hSliderValue1 inside a new group.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ZoomMoveTestWindow: EditorWindow
{
private static float kEditorWindowTabHeight = 20;
private static Matrix4x4 _prevGuiMatrix;
public static float hSliderValue1 = 0;
public static float hSliderValue2 = 0;
Rect[] wr = new Rect[]{
new Rect(0, 0, 100, 100),
new Rect(50, 50, 100, 100),
new Rect(100, 100, 100, 100)
};
[MenuItem("Window/Zoom Test #%w")]
private static void Init()
{
ZoomMoveTestWindow window = EditorWindow.GetWindow<ZoomMoveTestWindow>("Zoom Test", true, new System.Type[] {
typeof(UnityEditor.SceneView),
typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow")});
window.Show();
EditorWindow.FocusWindowIfItsOpen<ZoomMoveTestWindow>();
}
public static Rect BeginZoomArea(Rect rect)
{
GUI.BeginGroup(rect);
GUI.BeginGroup(new Rect(hSliderValue1, 0, 200, 200));
_prevGuiMatrix = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(new Vector2(hSliderValue2, 0), Quaternion.identity, Vector3.one);
return new Rect();
}
public static void EndZoomArea()
{
GUI.EndGroup();
GUI.matrix = _prevGuiMatrix;
GUI.EndGroup();
GUI.BeginGroup(new Rect(0.0f, kEditorWindowTabHeight, Screen.width, Screen.height - (kEditorWindowTabHeight + 3)));
}
public void OnGUI()
{
GUI.EndGroup(); //End the group that Unity began so we're not bound by the EditorWindow
BeginZoomArea(new Rect(10,10, 200, 200));
BeginWindows();
wr[0] = GUI.Window(0, wr[0], DrawWindow, "hello");
wr[1] = GUI.Window(1, wr[1], DrawWindow, "world");
wr[2] = GUI.Window(2, wr[2], DrawWindow, "!");
EndWindows();
EndZoomArea();
hSliderValue1 = GUI.HorizontalSlider(new Rect(250, 5, 100, 30), hSliderValue1, 0, 100);
hSliderValue2 = GUI.HorizontalSlider(new Rect(250, 35, 100, 30), hSliderValue2, 0, 100);
}
void DrawWindow(int id)
{
GUI.Button(new Rect(0, 30, 100, 50), "Wee!");
GUI.DragWindow();
}
}
It works but I don't know why. Because the interaction of GUI.matrix and BeginGroup(rect) is unknown.
PS: This post may help you.

R cannot be resolved to a variable why?

I have this
public GamePanel(Context context, Game game,int ScreenWidth,int Screenheigt) {
super(context);
getHolder().addCallback(this);
this.game = game;
thread = new MainThread(getHolder(),this);
background = new Background(BitmapFactory.decodeResource(getResources(), R.drawable.game_fon), ScreenWidth, this);
BM = new Barriermanager(BitmapFactory.decodeResource(getResources(), R.drawable.barier), this);
BM.setScreen(ScreenWidth, Screenheigt);
ship = new Ship(BitmapFactory.decodeResource(getResources(), R.drawable.player), 100, 0, ScreenWidth, Screenheigt);
coin = new Bonus(BitmapFactory.decodeResource(getResources(), R.drawable.bonus), -200,-200);
ArrayList<Bitmap> animation = new ArrayList<Bitmap>();
animation.add(BitmapFactory.decodeResource(getResources(), R.drawable.boom1));
animation.add(BitmapFactory.decodeResource(getResources(), R.drawable.boom2));
animation.add(BitmapFactory.decodeResource(getResources(), R.drawable.boom3));
animation.add(BitmapFactory.decodeResource(getResources(), R.drawable.boom4));
ship.setBoomAnimation(animation);
please help! The "R" cannot be resolved to a variable

AndroidPlot: How to combine different chart types on the one plot?

How to combine line chart and bar chart on the one plot? The documentation does not mention about this functionality. Is this possible for AndroidPlot?
Use this in oncreate() of ur activity.
setContentView(R.layout.main);
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
Number[] series1Numeros = { 1, 8, 5, 2, 7, 4 };
XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numeros),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Intereses");
XYSeries series = new SimpleXYSeries(Arrays.asList(new Number[] { 1, 2, 3, 4, 5 }),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "title");
BarFormatter formatter = new BarFormatter(Color.rgb(0, 200, 0), Color.rgb(100, 0, 0));
plot.addSeries(series, BarRenderer.class, formatter);
BarRenderer renderer = (BarRenderer) plot.getRenderer(BarRenderer.class);
LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 200, 0),
Color.rgb(0, 100, 0),
null);
plot.addSeries(series1, series1Format);

textPane cannot be resolved

I am writing a program in eclipse that generates reports based on inputs from a user. I have a JTextPane in a JScrollPane to allow the user to enter a description of the text, then add it to the system by pressing a button, but I am getting the error "textPaneDescription cannot be resolved".
The code(excluding imports)
public class GUI{
private JFrame frame;
private JTextField textFieldHoursWorked;
private JTextField textFieldParking;
private JTextField textFieldCongestion;
private JTextField textFieldDays;
private JTextField textFieldSmallTools;
private JTextField textFieldHireCharges;
private JTextField textFieldMaterials;
private JTextField textFieldSubContracted;
private JTextField textFieldSupplyOnlyWorks;
private JTextField textFieldConsultants;
private int counter = 0;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI window = new GUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public GUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
final ArrayList<Operative> tierOneArray = new ArrayList();
final ArrayList<Operative> tierTwoArray = new ArrayList();
final ArrayList<Operative> semiSkilledArray = new ArrayList();
final ArrayList<Operative> supervisionArray = new ArrayList();
frame = new JFrame();
frame.setBounds(100, 100, 780, 555);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JScrollPane scrollPaneHistory = new JScrollPane();
scrollPaneHistory.setBounds(353, 0, 411, 516);
frame.getContentPane().add(scrollPaneHistory);
final JTextArea textAreaHistory = new JTextArea();
textAreaHistory.setEditable(false);
scrollPaneHistory.setViewportView(textAreaHistory);
final JComboBox comboBoxOperativeType = new JComboBox();
comboBoxOperativeType.setModel(new DefaultComboBoxModel(new String[] {"Skilled Operative (Tier 1)", "Skilled Operative (Tier 2)", "Semi-skilled Operative", "Supervision"}));
comboBoxOperativeType.setBounds(139, 52, 182, 20);
frame.getContentPane().add(comboBoxOperativeType);
JLabel lblOperativeType = new JLabel("Operative Type");
lblOperativeType.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblOperativeType.setBounds(35, 52, 99, 20);
frame.getContentPane().add(lblOperativeType);
JLabel lblHoursWorked = new JLabel("Hours Worked");
lblHoursWorked.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblHoursWorked.setBounds(40, 114, 89, 20);
frame.getContentPane().add(lblHoursWorked);
textFieldHoursWorked = new JTextField();
textFieldHoursWorked.setBounds(139, 114, 182, 20);
frame.getContentPane().add(textFieldHoursWorked);
textFieldHoursWorked.setColumns(10);
final JComboBox comboBoxWorkingHours = new JComboBox();
comboBoxWorkingHours.setModel(new DefaultComboBoxModel(new String[] {"In", "Out"}));
comboBoxWorkingHours.setBounds(139, 145, 182, 20);
frame.getContentPane().add(comboBoxWorkingHours);
JLabel lblNewLabelWorkingHours = new JLabel("In/Out of Hours");
lblNewLabelWorkingHours.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabelWorkingHours.setBounds(35, 145, 99, 20);
frame.getContentPane().add(lblNewLabelWorkingHours);
final JRadioButton rdbtnEmergency = new JRadioButton("Emergency?");
rdbtnEmergency.setFont(new Font("Tahoma", Font.PLAIN, 14));
rdbtnEmergency.setForeground(new Color(0, 0, 0));
rdbtnEmergency.setBounds(135, 233, 20, 23);
frame.getContentPane().add(rdbtnEmergency);
JLabel lblParking = new JLabel("Parking");
lblParking.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblParking.setBounds(84, 176, 45, 18);
frame.getContentPane().add(lblParking);
textFieldParking = new JTextField();
textFieldParking.setColumns(10);
textFieldParking.setBounds(139, 176, 182, 20);
frame.getContentPane().add(textFieldParking);
JLabel lblCongestion = new JLabel("Congestion");
lblCongestion.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblCongestion.setBounds(60, 205, 69, 18);
frame.getContentPane().add(lblCongestion);
textFieldCongestion = new JTextField();
textFieldCongestion.setColumns(10);
textFieldCongestion.setBounds(139, 206, 182, 20);
frame.getContentPane().add(textFieldCongestion);
JLabel lblEmergency = new JLabel("Emergency?");
lblEmergency.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblEmergency.setBounds(51, 235, 83, 18);
frame.getContentPane().add(lblEmergency);
JButton btnAddOne = new JButton("Add");
btnAddOne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
counter ++;
Labourer t1Operative = new Labourer("Tier 1", 29.75, 39.67, 39.67, 52.89, 45.00, 85.00);
Labourer t2Operative = new Labourer("Tier 2", 32.98, 43.97, 43.97, 58.63, 45.00, 85.00);
Labourer semiSkilledOperative = new Labourer("Semi Skilled", 25.50, 34.00, 34.00, 45.33, 45.00, 85.00);
Labourer supervisionOperative = new Labourer("Tier 2", 34.00, 45.33, 45.33, 60.44, 65.00, 100.00);
if(comboBoxOperativeType.getSelectedIndex() == 0)
{
tierOneArray.add(new Operative(textPaneDescription.getText(), (String)comboBoxOperativeType.getSelectedItem(), textFieldDays.getText(), textFieldHoursWorked.getText(), (String)comboBoxWorkingHours.getSelectedItem(),textFieldParking.getText(), textFieldCongestion.getText(), rdbtnEmergency.isSelected(), t1Operative));
}
else if(comboBoxOperativeType.getSelectedIndex() == 1)
{
tierTwoArray.add(new Operative(textPaneDescription.getText(), (String)comboBoxOperativeType.getSelectedItem(), textFieldDays.getText(), textFieldHoursWorked.getText(), (String)comboBoxWorkingHours.getSelectedItem(),textFieldParking.getText(), textFieldCongestion.getText(), rdbtnEmergency.isSelected(), t2Operative));
}
else if(comboBoxOperativeType.getSelectedIndex() == 2)
{
semiSkilledArray.add(new Operative(textPaneDescription.getText(), (String)comboBoxOperativeType.getSelectedItem(), textFieldDays.getText(), textFieldHoursWorked.getText(), (String)comboBoxWorkingHours.getSelectedItem(),textFieldParking.getText(), textFieldCongestion.getText(), rdbtnEmergency.isSelected(), semiSkilledOperative));
}
else if(comboBoxOperativeType.getSelectedIndex() == 3)
{
supervisionArray.add(new Operative(textPaneDescription.getText(), (String)comboBoxOperativeType.getSelectedItem(), textFieldDays.getText(), textFieldHoursWorked.getText(), (String)comboBoxWorkingHours.getSelectedItem(),textFieldParking.getText(), textFieldCongestion.getText(), rdbtnEmergency.isSelected(), supervisionOperative));
}
textAreaHistory.append(counter + ": " + (String)comboBoxOperativeType.getSelectedItem() + " / " + textFieldDays.getText()+ "day(s) / " + textFieldHoursWorked.getText() + "hours(s) / " + (String)comboBoxWorkingHours.getSelectedItem() + " / £" + textFieldParking.getText() + " / £" + textFieldCongestion.getText() + " / " + rdbtnEmergency.isSelected() + "\n");
}
});
btnAddOne.setBounds(231, 235, 89, 23);
frame.getContentPane().add(btnAddOne);
JButton btnDone = new JButton("Done");
btnDone.setBounds(231, 480, 89, 23);
btnDone.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Logic logic = new Logic(tierOneArray, tierTwoArray, semiSkilledArray, supervisionArray);
}
});
frame.getContentPane().add(btnDone);
JLabel labelDays = new JLabel("Days Worked");
labelDays.setFont(new Font("Tahoma", Font.PLAIN, 14));
labelDays.setBounds(45, 83, 89, 20);
frame.getContentPane().add(labelDays);
textFieldDays = new JTextField();
textFieldDays.setColumns(10);
textFieldDays.setBounds(139, 83, 182, 20);
frame.getContentPane().add(textFieldDays);
JSeparator separator = new JSeparator();
separator.setBounds(0, 270, 352, 2);
frame.getContentPane().add(separator);
JLabel lblSmallTools = new JLabel("Small Tools and Incidental Costs");
lblSmallTools.setBounds(8, 308, 219, 14);
frame.getContentPane().add(lblSmallTools);
textFieldSmallTools = new JTextField();
lblSmallTools.setLabelFor(textFieldSmallTools);
textFieldSmallTools.setBounds(199, 305, 141, 20);
frame.getContentPane().add(textFieldSmallTools);
textFieldSmallTools.setColumns(10);
JLabel lblHireCharges = new JLabel("Hire Charges");
lblHireCharges.setBounds(118, 283, 128, 14);
frame.getContentPane().add(lblHireCharges);
textFieldHireCharges = new JTextField();
textFieldHireCharges.setColumns(10);
textFieldHireCharges.setBounds(199, 280, 141, 20);
frame.getContentPane().add(textFieldHireCharges);
JLabel lblMaterials = new JLabel("Material Purchase Costs");
lblMaterials.setBounds(51, 333, 181, 14);
frame.getContentPane().add(lblMaterials);
textFieldMaterials = new JTextField();
textFieldMaterials.setColumns(10);
textFieldMaterials.setBounds(199, 333, 141, 20);
frame.getContentPane().add(textFieldMaterials);
JLabel lblSubcontracted = new JLabel("Specialist Subcontraced Works");
lblSubcontracted.setBounds(10, 361, 212, 14);
frame.getContentPane().add(lblSubcontracted);
textFieldSubContracted = new JTextField();
textFieldSubContracted.setColumns(10);
textFieldSubContracted.setBounds(199, 358, 141, 20);
frame.getContentPane().add(textFieldSubContracted);
JLabel lblSupplyOnlyWorks = new JLabel("Supply Only Works");
lblSupplyOnlyWorks.setBounds(80, 389, 116, 17);
frame.getContentPane().add(lblSupplyOnlyWorks);
textFieldSupplyOnlyWorks = new JTextField();
textFieldSupplyOnlyWorks.setColumns(10);
textFieldSupplyOnlyWorks.setBounds(199, 387, 141, 20);
frame.getContentPane().add(textFieldSupplyOnlyWorks);
JLabel lblConsultants = new JLabel("Consultants and Designers");
lblConsultants.setBounds(35, 417, 206, 14);
frame.getContentPane().add(lblConsultants);
textFieldConsultants = new JTextField();
textFieldConsultants.setColumns(10);
textFieldConsultants.setBounds(199, 414, 141, 20);
frame.getContentPane().add(textFieldConsultants);
JButton btnAddTwo = new JButton("Add");
btnAddTwo.setBounds(232, 446, 89, 23);
frame.getContentPane().add(btnAddTwo);
JLabel lblDescription = new JLabel("Description");
lblDescription.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblDescription.setBounds(60, 23, 69, 20);
frame.getContentPane().add(lblDescription);
JScrollPane scrollPaneDescription = new JScrollPane();
scrollPaneDescription.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPaneDescription.setBounds(139, 23, 182, 20);
frame.getContentPane().add(scrollPaneDescription);
JTextPane textPaneDescription = new JTextPane();
scrollPaneDescription.setViewportView(textPaneDescription);
}
}
It looks like you are accessing the variable textPaneDescription before you actually declared it.
You access the textPaneDescription when adding an action listener.
tierOneArray.add(new Operative(textPaneDescription.getText() ... );
While not only till later in the code you declare the variable, thus it can not be resolved.