Metoda lokalizacyjna

0

Witam

Mam problem z metoda lokalizacyjna. Mam aplikacje ktora ma dzialac w 2 jezykach na 1 rzut oka kod wyglada wporzadku. Jednak sie nie kompiluje poprawnie i wyrzuca bledy. Nie wiem co jest nie tak?

Prosze o pomoc. Sorry za mega długi kod nie interesuje mnie na razie problem dlaczego nie rysuje wykresu tylko dlaczego nie dzila metoda lokalizacyjna.
Podziw dla tych co się im zechce przekleic ten kod do kompilatora:

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import java.text.*;
import javax.swing.*;

public class Retire extends JApplet
{ 
	/**
	 * 
	 */

	public void init()

{
		EventQueue.invokeLater(new Runnable(){
			public void run(){
		
				initUI();
			}
		});
}

public void initUI()

{
	setLayout(new GridBagLayout());

	add(languageLabel, new GBC(0, 0 ).setAnchor(GBC.EAST));
	add(savingsLabel, new GBC(0, 1 ).setAnchor(GBC.EAST));
	add(contribLabel, new GBC(2, 1 ).setAnchor(GBC.EAST));
	add(incomeLabel, new GBC(4, 1 ).setAnchor(GBC.EAST));
	add(currentAgeLabel, new GBC(0, 2 ).setAnchor(GBC.EAST));
	add(retireAgeLabel, new GBC(2, 2 ).setAnchor(GBC.EAST));
	add(deathAgeLabel, new GBC(4, 2 ).setAnchor(GBC.EAST));
	add(inflationPercentLabel, new GBC(0, 3 ).setAnchor(GBC.EAST));
	add(investPercentLabel, new GBC(2, 3 ).setAnchor(GBC.EAST));
	add(localeCombo, new GBC(1,0, 3, 1));
	add(savingsField, new GBC(1,1).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(contribField, new GBC(3,1).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(incomeField, new GBC(5,1).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(currentAgeField, new GBC(1,2).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(deathAgeField, new GBC(3,2).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(retireAgeField, new GBC(5,2).setWeight(100, 0).setFill((GBC.HORIZONTAL)));
	add(inflationPercentField,new GBC(1,3).setWeight(100,0).setFill(GBC.HORIZONTAL));
	add(investPercentField,new GBC(3,3).setWeight(100,0).setFill(GBC.HORIZONTAL));
	add(retireCanvas,new GBC(0,4,4,1).setWeight(100,100).setFill(GBC.BOTH));
	add(new JScrollPane(retireText), new GBC(4,4,2,1).setWeight(0, 100).setFill(GBC.BOTH));
	computeButton.setName("computeButton");
	computeButton.addActionListener( new ActionListener(){
		public void actionPerformed(ActionEvent event)

		{

			getInfo();
			updateData();
			updateGraph();

		}

	});

	add(computeButton, new GBC(5,3));
	retireText.setEditable(false);
	retireText.setFont(new Font ("Monospaced", Font.PLAIN, 10));

	info.setSavings(0);
	info.setContrib(9000);
	info.setIncome(60000);
	info.setCurrentAge(35);
	info.setRetireAge(65);
	info.setDeathAge(85);
	info.setInvestPercent(0.1);
	info.setInflationPercent(0.05);

	int localeIndex = 0 ;
	for(int i = 0; i< locales.length; i++)

		if(getLocale().equals(locales[i]))localeIndex = i;

	setCurrentLocale(locales[localeIndex]);

	localeCombo.addActionListener(new ActionListener()

	{

		public void actionPerformed(ActionEvent event){

			setCurrentLocale((Locale) localeCombo.getSelectedItem());

		}

	});

	}

	public void setCurrentLocale(Locale locale)

	{

	currentLocale = locale;
	localeCombo.setSelectedItem(currentLocale);	
	localeCombo.setLocale(currentLocale);	
	res= ResourceBundle.getBundle("RetireResources",currentLocale);	
	resStrings = ResourceBundle.getBundle("RetireStrings", currentLocale);	
	numberFmt= NumberFormat.getNumberInstance(currentLocale);	
	currencyFmt=NumberFormat.getCurrencyInstance(currentLocale);	
	percentFmt = NumberFormat.getPercentInstance(currentLocale);
	
	updateDisplay();	
	updateInfo();
	updateData();
	updateGraph();
	
	}


	public void updateDisplay()
	{
	languageLabel.setText(resStrings.getString("language"));
	savingsLabel.setText(resStrings.getString("savings"));
	contribLabel.setText(resStrings.getString("contrib"));
	incomeLabel.setText(resStrings.getString("income"));
	currentAgeLabel.setText(resStrings.getString("currentAge"));
	retireAgeLabel.setText(resStrings.getString("retireAge"));
	deathAgeLabel.setText(resStrings.getString("deathAge"));
	inflationPercentLabel.setText(resStrings.getString("inflation"));
	investPercentLabel.setText(resStrings.getString("invest"));
	computeButton.setText(resStrings.getString("computeButton"));
	
	}

	public void updateInfo()
	{
	savingsField.setText(currencyFmt.format(info.getSavings()));
	contribField.setText(currencyFmt.format(info.getContrib()));
	incomeField.setText(currencyFmt. format(info.getIncome()));
	currentAgeField.setText(numberFmt.format(info.getCurrentAge()));
	retireAgeField.setText(numberFmt.format(info.getRetireAge()));
	deathAgeField.setText(numberFmt.format(info.getDeathAge()));
	investPercentField.setText(percentFmt.format(info.getInvestPercent()));
	inflationPercentField.setText(percentFmt.format(info.getInflationPercent()));
	}
	
	public void updateData()
	{
		retireText.setText("");
		MessageFormat retireMsg = new MessageFormat("");
		retireMsg.setLocale(currentLocale);
		retireMsg.applyPattern(resStrings.getString("retire"));
		
		for (int i = info.getCurrentAge(); i <= info.getDeathAge(); i++)
		{
			Object[]args = {i, info.getBalance(i)};
			retireText.append(retireMsg.format(args)+ "\n");
			
		}
	}
	
	public void updateGraph()
	{
		retireCanvas.setColorPre((Color) res.getObject("colorPre"));
		retireCanvas.setColorGain((Color) res.getObject("colorGain"));
		retireCanvas.setColorLoss((Color) res.getObject("colorLoss"));
		retireCanvas.setInfo(info);
		repaint();
	}
	
	public void getInfo()
	{
		try
		{
			info.setSavings(currencyFmt.parse(savingsField.getText()).doubleValue());
			info.setContrib(currencyFmt.parse(contribField.getText()).doubleValue());
			info.setIncome(currencyFmt.parse(incomeField.getText()).doubleValue());
			info.setCurrentAge(numberFmt.parse(currentAgeField.getText()).intValue());
			info.setRetireAge(numberFmt.parse(retireAgeField.getText()).intValue());
			info.setDeathAge(numberFmt.parse(deathAgeField.getText()).intValue());
			info.setInvestPercent(percentFmt.parse(investPercentField.getText()).doubleValue());
			info.setInflationPercent(percentFmt.parse(inflationPercentField.getText()).doubleValue());
		}
		catch(ParseException e)
		{
			
		}
		}
	private JTextField savingsField = new JTextField(10);
	private JTextField contribField = new JTextField(10);
	private JTextField incomeField = new JTextField(10);
	private JTextField currentAgeField = new JTextField(4);
	private JTextField retireAgeField = new JTextField(4);
	private JTextField deathAgeField = new JTextField(4);
	private JTextField investPercentField = new JTextField(6);
	private JTextField inflationPercentField = new JTextField(6);

	private JTextArea retireText = new JTextArea(10,25);
	private RetireCanvas retireCanvas= new RetireCanvas();
	private JButton computeButton = new JButton();
	private JLabel languageLabel = new JLabel();
	private JLabel savingsLabel = new JLabel();
	private JLabel contribLabel = new JLabel();
	private JLabel incomeLabel = new JLabel();
	private JLabel currentAgeLabel = new JLabel();
	private JLabel retireAgeLabel = new JLabel();
	private JLabel deathAgeLabel = new JLabel();
	private JLabel inflationPercentLabel = new JLabel();
	private JLabel investPercentLabel = new JLabel();
	
	private RetireInfo info = new RetireInfo();
	
	private Locale[]locales = {Locale.US,  Locale.GERMANY};
	private Locale currentLocale;
	private JComboBox localeCombo = new JComboBox(locales);
	private ResourceBundle res;
	private ResourceBundle resStrings;
	private NumberFormat currencyFmt;
	private NumberFormat numberFmt;
	private NumberFormat percentFmt;
}
class RetireInfo
{
	public double getBalance(int year)
	{
		if(year<currentAge)return 0;
		else if(year == currentAge)
		{
			age=year;
			balance = savings;
			return balance;
			
		}
		else if(year==age)return balance;
		if(year !=age+1) getBalance(year -1);
		age=year;
		if (age < retireAge) balance += contrib;
		else balance -= income;
		balance = balance *(1+(investPercent - inflationPercent));
		return balance;
		
	}
	public double getSavings()
	{
	return savings;
	}
	
	public void setSavings(double newValue)
	{
		savings = newValue;
	}
	public double getContrib()
	{
		return contrib;
	}
	public void setContrib(double newValue)
	{
		contrib = newValue;
	}
	public double getIncome()
	{
		return income;
	}
	public void setIncome(double newValue)
	{
		income = newValue;
	}
	public int getCurrentAge()
	{
		return currentAge;
		
	}
	public void setCurrentAge(int newValue)
	{
		currentAge= newValue;
	}
	public int getRetireAge()
	{
		return retireAge;
	}
	public void setRetireAge(int newValue)
	{
		retireAge= newValue;
	}
	public int getDeathAge()
	{
		return deathAge;
	}
	public void setDeathAge(int newValue)
	{
		deathAge =newValue;
	}
	public double getInflationPercent()
	{
		return inflationPercent;
	}
	
	public void setInflationPercent(double newValue)
	{
		inflationPercent  = newValue;
	}
	public double getInvestPercent()
	{
		return investPercent;
	}
	
	public void setInvestPercent(double newValue)
	{
		investPercent  = newValue;
	}
	
private double savings;
private double contrib;
private double income;
private int currentAge;
private int retireAge;
private int deathAge;
private double inflationPercent;
private double investPercent;

private int age;
private double balance;
}


class RetireCanvas extends JPanel
{
	public RetireCanvas()
	{
		setSize(PANEL_WIDTH, PANEL_HEIGHT);
	}
	
	public void setInfo(RetireInfo newInfo)
	{
		info = newInfo;
		repaint();
	}
	
	public void paintComponent(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		if (info==null) return;
		
		
		double minValue = 0;
		double maxValue = 0;
		int i;
		for(i = info.getCurrentAge();i<= info.getDeathAge(); i++)
		{
			double v = info.getBalance(i);
			if(minValue>v) minValue = v;
			if(maxValue<v) maxValue = v;
			
		}
		if(maxValue==minValue) return;
		
		int barWidth = getWidth()/(info.getDeathAge()-info.getCurrentAge()+1);
		double scale=getHeight()/(maxValue-minValue);
		
		for(i= info.getCurrentAge(); i<=info.getDeathAge();i++);
		{
			int x1 = (i - info.getCurrentAge())*barWidth +1;
			int y1;
			double v= info.getBalance(i);
			int height;
			int yOrigin = (int)(maxValue*scale);
			 if(v>=0)
			 {
				 y1 = (int)((maxValue - v)*scale);
				 height = yOrigin - y1;
			 }
			 else
			 {
				 y1=yOrigin;
				 height  =(int)(-v*scale);
			 }
			 
			 if(i<info.getRetireAge())  g2.setPaint(colorPre);
			 else if ( v>= 0) ((Graphics2D) g2).setPaint(colorGain);
			 else  g2.setPaint(colorLoss);
			 Rectangle2D bar = new Rectangle2D.Double(x1,y1,barWidth-2,height);
			 g2.fill(bar);
			 g2.setPaint(Color.black);
			 g2.draw(bar);
		}
	}
	public void setColorPre(Color color)
	{
		colorPre = color;
		repaint();
			 
	}
	public void setColorGain(Color color)
	{
		colorGain=color;
		repaint();
	}
	
	public void setColorLoss(Color color)
	{
		colorLoss= color;
		repaint();
	}
	
	private RetireInfo info=null;
	private Color colorPre;
	private Color colorGain;
	private Color colorLoss;
	private static final int PANEL_WIDTH = 400;
	private static final int PANEL_HEIGHT = 400;
}


import java.awt.*;

public class GBC extends GridBagConstraints

{
public GBC(int gridx, int gridy)
{
this.gridx = gridx;
this.gridy = gridy;
}
public GBC(int gridx, int gridy, int gridwidth, int gridheight)
{
this.gridx = gridx;
this.gridy = gridy;
this.gridwidth = gridwidth;
this.gridheight = gridheight;
}
public GBC setAnchor(int anchor)
{
this.anchor = anchor;

return this;
}

public GBC setFill(int fill)
{
this.fill = fill;
return this;
}
public GBC setWeight(double weightx, double weighty)
{
this.weightx = weightx;
this.weighty = weighty;
return this;
}
public GBC setInsets(int distance)
{
this.insets = new Insets(distance, distance, distance, distance);
return this;
}
public GBC setInsets(int top, int left, int bottom, int right)
{
this.insets = new Insets(top, left, bottom, right);
return this;
}
public GBC setIpad(int ipadx, int ipady)
{
this.ipadx = ipadx;
this.ipady = ipady;

return this;

}

}

import java.awt.Color;

public class RetireResources extends java.util.ListResourceBundle{
public Object[][] getContents(){return contents;}
static final Object[][]contents = {
{"colorPre",Color.blue},
{"colorGain",Color.white},
{"colorLoss", Color.red}

	};
}

import java.awt.Color;
import java.util.*;

public class RetireResources_de extends java.util.ListResourceBundle{
public Object[][] getContents(){return contents;}
static final Object[][]contents = {
{"colorPre",Color.blue},
{"colorGain",Color.white},
{"colorLoss", Color.red}

	};
}

 2 dokumenty textowy o nazwie RetireStrings_de i 2 RetireStrings

language=Sprache
computeButton= Rechnen	
savings= Vorherige Ersparnisse
contrib =  J\u00e4hrliche Einzahlung
income =  Einkommen nach Ruhestand
currentAge = Jetziges Alter
retireAge = Ruhestandsalter	
deathAge = Lebenserwartung
inflationPercent = Inflation
investPercent = Investitiongewinn
retire= Alter : {0, number} Guthaben: {1,number,currency}


2 RetireStrings

language=Language
computeButton=Compute
savings=Prior Savings
contrib = Annual Contribution
income = Retirement Income
currentAge = current Age
retireAge = retire Age
deathAge= Life Expectancy
inflationPercent = Inflation
investPercent = Investment Return
retire=Age: {0,number} Balance: {1,number,currency}
0

Najważniejsza informacja. Jakie błędy.

0

Po adpaleniu apletu na konsoli wyrzuca:

Exception in thread "AWT-EventQueue-1" java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key inflation
at java.util.ResourceBundle.getObject(Unknown Source)
at java.util.ResourceBundle.getString(Unknown Source)
at Retire.updateDisplay(Retire.java:128)
at Retire.setCurrentLocale(Retire.java:111)
at Retire.initUI(Retire.java:82)
at Retire$1.run(Retire.java:20)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

0

at Retire.updateDisplay(Retire.java:128)

No to zobacz, co masz w Retire.java w linii 128.

1 użytkowników online, w tym zalogowanych: 0, gości: 1