import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class DollarStoreBennettJordan extends JApplet implements ActionListener
{
JFrame frame = new JFrame();
JLabel n1 = new JLabel("Enter sales person number(1-4): ");
JTextField tf1 = new JTextField(5);
JLabel n2 = new JLabel("Enter product number(1-5): ");
JTextField tf2 = new JTextField(5);
JLabel n3 = new JLabel("Enter sales amount(0.01-0.99): ");
JTextField tf3 = new JTextField(5);
JTextArea ta = new JTextArea(8,58);
JButton b1 = new JButton("Submit");
JButton b2 = new JButton("Clear");
double[][] sales = {
{ 0.00, 0.00, 0.00, 0.00, 0.00 },
{ 0.00, 0.00, 0.00, 0.00, 0.00 },
{ 0.00, 0.00, 0.00, 0.00, 0.00 },
{ 0.00, 0.00, 0.00, 0.00, 0.00 }
};
double[] product_totals = new double [sales.length];
int total;
public void init()
{
setLayout(new FlowLayout(FlowLayout.CENTER));
add(n1);
add(tf1);
add(n2);
add(tf2);
add(n3);
add(tf3);
add(ta);
add(b1);
add(b2);
ta.setEditable(false);
ta.setFont(new Font("Courier", Font.BOLD, 10));
b1.addActionListener(this);
b2.addActionListener(this);
}
private boolean emptyFields()
{
boolean result;
if(tf1.getText().equals("")) //check tf1
{
result = true;
tf1.requestFocus();
showStatus("Please enter a value for salesperson number");
}
else
{
result = false;
}
if(tf2.getText().equals("")) //check tf2
{
result = true;
tf2.requestFocus();
showStatus("Please enter an item number");
}
else
{
result = false;
}
if(tf3.getText().equals("")) //check tf3
{
result = true;
tf3.requestFocus();
showStatus("Please enter a valid price");
}
else
{
result = false;
}
return result;
}
public void actionPerformed(ActionEvent e)
{
showStatus("");
if (e.getSource() == b2)
{
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf1.requestFocus();
}
else if (e.getSource() == b1)
{
emptyFields();
drawSummary();
}
}
private void drawSummary()
{
ta.setText("");
DecimalFormat money = new DecimalFormat("0.00");
for (int r = 0; r < sales.length; r++)
{
total = 0;
for (int c = 0; c < sales[0].length; c++)
{
total += sales[r][c];
}
product_totals[r] = total;
}
for (int i = 0; i < sales.length; i++)
{
}
}
private void drawSeparators(char separator)
{
}
}
嘿那里,我希望有人可以帮助我。我在让数组销售显示在JTextArea中时遇到问题。完成后,applet应该为销售人员,项目和价格获取输入,并使用输入来更新阵列。我还是初学者,所以我不知道如何在文本区域显示数组,然后用输入更新它,从那里去哪里。谢谢,任何帮助表示赞赏。