我正在创建一个产品计算器类应用程序,当我以较低分辨率打开程序时,我正在努力扩展。以下是我希望程序看起来的方式:
它在较低分辨率下的外观(在此图中为1366x768):
我正在为我的应用程序使用migLayout,我将发布以下代码
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.Box;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.text.NumberFormat;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.SwingConstants;
import javax.swing.JSeparator;
import javax.swing.JTextPane;
import net.miginfocom.swing.MigLayout;
public class FinalProject {
private JFrame frame;
private static JTextField txtLatexA;
private static JTextField textField_1;
private static JTextField textField_2;
private static JTextField textField_3;
private static JTextField textField_4;
private static JTextField txtPairsYear;
private static JTextField txtLatexB;
private static JTextField txtSyntheticA;
private static JTextField txtSyntheticB;
private static JTextField textField_9;
private static JTextField textField_10;
private static JTextField textField_11;
private static JTextField textField_12;
private static JTextField textField_13;
private static JTextField textField_14;
private static JTextField textField_15;
private static JTextField textField_16;
private static JTextField textField_17;
private static JTextField textField_18;
private static JTextField textField_19;
private static JTextField textField_20;
private static JTextField textField_23;
private static JTextField txtOfTotal;
private static JTextField txtPricePerPair;
private static JTextField txtTotalPrice;
private static JButton btnNewButton;
private static JTextField textField;
private static JTextField textField_5;
private static JTextField textField_6;
private static JTextField textField_7;
private static JTextField textField_8;
private static JTextField textField_21;
private static JTextField textField_22;
private static JTextField textField_24;
private static JTextField textField_29;
private static JTextField textField_30;
private static JTextField textField_31;
private static JTextField textField_32;
private static JTextField textField_33;
private static JTextField textField_34;
private static JTextField textField_35;
private static JTextField textField_36;
private static JTextField textField_37;
private static JTextField textField_38;
private static JTextField textField_39;
private static JTextField textField_40;
private static JTextField textField_41;
private static JTextField textField_42;
private static JTextField textField_25;
private static JTextField textField_26;
private static JTextField textField_27;
private static JTextField textField_28;
private static JButton btnNewButton_1;
private static JTextField textField_43;
private static JTextField txtPriceReduction;
private static JTextField textField_44;
private static JTextField textField_45;
private static JButton btnNewButton_2;
private static JTextField textField_46;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FinalProject window = new FinalProject();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public FinalProject() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
// 2525, 939
frame = new JFrame();
frame.setBounds(100, 100, 1366, 768);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new MigLayout("", "[206px][9px][206px][206px][206px][206px][3px][20px][15px][2px][189px][10px][206px][206px][13px][65px][22px][119px][11px][76px][22px][216px]", "[77px][24px][77px][10px][77px][12px][77px][12px][77px][15px][104px][30px][2px][66px][77px][9px][77px]"));
txtLatexA = new JTextField();
txtLatexA.setFont(new Font("Tahoma", Font.PLAIN, 36));
txtLatexA.setText("Latex A");
frame.getContentPane().add(txtLatexA, "cell 0 2,grow");
txtLatexA.setColumns(10);
textField_1 = new JTextField();
textField_1.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_1.setColumns(10);
frame.getContentPane().add(textField_1, "cell 2 2,grow");
textField_2 = new JTextField();
textField_2.setEditable(false);
textField_2.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_2.setColumns(10);
frame.getContentPane().add(textField_2, "cell 3 2,grow");
textField_3 = new JTextField();
textField_3.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_3.setColumns(10);
frame.getContentPane().add(textField_3, "cell 4 2,grow");
textField_4 = new JTextField();
textField_4.setEditable(false);
textField_4.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_4.setColumns(10);
frame.getContentPane().add(textField_4, "cell 5 2,grow");
txtPairsYear = new JTextField();
txtPairsYear.setEditable(false);
txtPairsYear.setFont(new Font("Tahoma", Font.PLAIN, 32));
txtPairsYear.setText("Pairs / Year");
txtPairsYear.setColumns(10);
frame.getContentPane().add(txtPairsYear, "cell 2 0,grow");
txtLatexB = new JTextField();
txtLatexB.setFont(new Font("Tahoma", Font.PLAIN, 36));
txtLatexB.setText("Latex B");
txtLatexB.setColumns(10);
frame.getContentPane().add(txtLatexB, "cell 0 4,grow");
txtSyntheticA = new JTextField();
txtSyntheticA.setFont(new Font("Tahoma", Font.PLAIN, 36));
txtSyntheticA.setText("Synthetic A");
txtSyntheticA.setColumns(10);
frame.getContentPane().add(txtSyntheticA, "cell 0 6,grow");
txtSyntheticB = new JTextField();
txtSyntheticB.setFont(new Font("Tahoma", Font.PLAIN, 36));
txtSyntheticB.setText("Synthetic B");
txtSyntheticB.setColumns(10);
frame.getContentPane().add(txtSyntheticB, "cell 0 8,grow");
textField_9 = new JTextField();
textField_9.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_9.setColumns(10);
frame.getContentPane().add(textField_9, "cell 2 4,grow");
textField_10 = new JTextField();
textField_10.setEditable(false);
textField_10.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_10.setColumns(10);
frame.getContentPane().add(textField_10, "cell 3 4,grow");
textField_11 = new JTextField();
textField_11.setEditable(false);
textField_11.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_11.setColumns(10);
frame.getContentPane().add(textField_11, "cell 5 4,grow");
textField_12 = new JTextField();
textField_12.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_12.setColumns(10);
frame.getContentPane().add(textField_12, "cell 4 4,grow");
textField_13 = new JTextField();
textField_13.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_13.setColumns(10);
frame.getContentPane().add(textField_13, "cell 2 6,grow");
textField_14 = new JTextField();
textField_14.setEditable(false);
textField_14.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_14.setColumns(10);
frame.getContentPane().add(textField_14, "cell 3 6,grow");
textField_15 = new JTextField();
textField_15.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_15.setColumns(10);
frame.getContentPane().add(textField_15, "cell 4 6,grow");
textField_16 = new JTextField();
textField_16.setEditable(false);
textField_16.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_16.setColumns(10);
frame.getContentPane().add(textField_16, "cell 5 6,grow");
textField_17 = new JTextField();
textField_17.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_17.setColumns(10);
frame.getContentPane().add(textField_17, "cell 2 8,grow");
textField_18 = new JTextField();
textField_18.setEditable(false);
textField_18.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_18.setColumns(10);
frame.getContentPane().add(textField_18, "cell 3 8,grow");
textField_19 = new JTextField();
textField_19.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_19.setColumns(10);
frame.getContentPane().add(textField_19, "cell 4 8,grow");
textField_20 = new JTextField();
textField_20.setEditable(false);
textField_20.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_20.setColumns(10);
frame.getContentPane().add(textField_20, "cell 5 8,grow");
textField_23 = new JTextField();
textField_23.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_23.setEditable(false);
textField_23.setColumns(10);
frame.getContentPane().add(textField_23, "cell 5 10,growx,aligny top");
txtOfTotal = new JTextField();
txtOfTotal.setEditable(false);
txtOfTotal.setFont(new Font("Tahoma", Font.PLAIN, 34));
txtOfTotal.setText("% Of Total");
txtOfTotal.setColumns(10);
frame.getContentPane().add(txtOfTotal, "cell 3 0,grow");
txtPricePerPair = new JTextField();
txtPricePerPair.setFont(new Font("Tahoma", Font.PLAIN, 30));
txtPricePerPair.setEditable(false);
txtPricePerPair.setText("Price Per Pair");
txtPricePerPair.setColumns(10);
frame.getContentPane().add(txtPricePerPair, "cell 4 0,grow");
txtTotalPrice = new JTextField();
txtTotalPrice.setEditable(false);
txtTotalPrice.setFont(new Font("Tahoma", Font.PLAIN, 32));
txtTotalPrice.setText("Total Price");
txtTotalPrice.setColumns(10);
frame.getContentPane().add(txtTotalPrice, "cell 5 0,grow");
btnNewButton = new JButton("Calculate Total");
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 36));
frame.getContentPane().add(btnNewButton, "cell 0 14 3 3,alignx left,growy");
textField = new JTextField();
textField.setEditable(false);
textField.setFont(new Font("Tahoma", Font.PLAIN, 36));
textField.setColumns(10);
frame.getContentPane().add(textField, "cell 8 2 3 1,grow");
textField_5 = new JTextField();
textField_5.setFont(new Font("Tahoma", Font.PLAIN, 36));
textField_5.setEditable(false);
textField_5.setColumns(10);
frame.getContentPane().add(textField_5, "cell 8 4 3 1,grow");
textField_6 = new JTextField();
textField_6.setEditable(false);
textField_6.setFont(new Font("Tahoma", Font.PLAIN, 36));
textField_6.setColumns(10);
frame.getContentPane().add(textField_6, "cell 8 6 3 1,grow");
textField_7 = new JTextField();
textField_7.setFont(new Font("Tahoma", Font.PLAIN, 36));
textField_7.setEditable(false);
textField_7.setColumns(10);
frame.getContentPane().add(textField_7, "cell 8 8 3 1,grow");
textField_8 = new JTextField();
textField_8.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_8.setColumns(10);
frame.getContentPane().add(textField_8, "cell 12 2,grow");
textField_21 = new JTextField();
textField_21.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_21.setColumns(10);
frame.getContentPane().add(textField_21, "cell 12 4,grow");
textField_22 = new JTextField();
textField_22.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_22.setColumns(10);
frame.getContentPane().add(textField_22, "cell 12 6,grow");
textField_24 = new JTextField();
textField_24.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_24.setColumns(10);
frame.getContentPane().add(textField_24, "cell 12 8,grow");
textField_29 = new JTextField();
textField_29.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_29.setEditable(false);
textField_29.setColumns(10);
frame.getContentPane().add(textField_29, "cell 13 2,grow");
textField_30 = new JTextField();
textField_30.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_30.setEditable(false);
textField_30.setColumns(10);
frame.getContentPane().add(textField_30, "cell 13 4,grow");
textField_31 = new JTextField();
textField_31.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_31.setEditable(false);
textField_31.setColumns(10);
frame.getContentPane().add(textField_31, "cell 13 6,grow");
textField_32 = new JTextField();
textField_32.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_32.setEditable(false);
textField_32.setColumns(10);
frame.getContentPane().add(textField_32, "cell 13 8,grow");
textField_33 = new JTextField();
textField_33.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_33.setEditable(false);
textField_33.setColumns(10);
frame.getContentPane().add(textField_33, "cell 15 2 3 1,grow");
textField_34 = new JTextField();
textField_34.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_34.setEditable(false);
textField_34.setColumns(10);
frame.getContentPane().add(textField_34, "cell 15 4 3 1,grow");
textField_35 = new JTextField();
textField_35.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_35.setEditable(false);
textField_35.setColumns(10);
frame.getContentPane().add(textField_35, "cell 15 6 3 1,grow");
textField_36 = new JTextField();
textField_36.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_36.setEditable(false);
textField_36.setColumns(10);
frame.getContentPane().add(textField_36, "cell 15 8 3 1,grow");
textField_37 = new JTextField();
textField_37.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_37.setEditable(false);
textField_37.setColumns(10);
frame.getContentPane().add(textField_37, "cell 19 2 3 1,alignx left,growy");
textField_38 = new JTextField();
textField_38.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_38.setEditable(false);
textField_38.setColumns(10);
frame.getContentPane().add(textField_38, "cell 19 4 3 1,alignx left,growy");
textField_39 = new JTextField();
textField_39.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_39.setEditable(false);
textField_39.setColumns(10);
frame.getContentPane().add(textField_39, "cell 19 6 3 1,alignx left,growy");
textField_40 = new JTextField();
textField_40.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_40.setEditable(false);
textField_40.setColumns(10);
frame.getContentPane().add(textField_40, "cell 19 8 3 1,alignx left,growy");
textField_41 = new JTextField();
textField_41.setEditable(false);
textField_41.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_41.setColumns(10);
frame.getContentPane().add(textField_41, "cell 8 10 3 1,growx,aligny top");
textField_42 = new JTextField();
textField_42.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_42.setEditable(false);
textField_42.setColumns(10);
frame.getContentPane().add(textField_42, "cell 19 10 3 1,alignx left,aligny top");
textField_25 = new JTextField();
textField_25.setText("Pairs / Year");
textField_25.setFont(new Font("Tahoma", Font.PLAIN, 32));
textField_25.setEditable(false);
textField_25.setColumns(10);
frame.getContentPane().add(textField_25, "cell 12 0,grow");
textField_26 = new JTextField();
textField_26.setText("% Of Total");
textField_26.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_26.setEditable(false);
textField_26.setColumns(10);
frame.getContentPane().add(textField_26, "cell 13 0,grow");
textField_27 = new JTextField();
textField_27.setText("Price Per Pair");
textField_27.setFont(new Font("Tahoma", Font.PLAIN, 32));
textField_27.setEditable(false);
textField_27.setColumns(10);
frame.getContentPane().add(textField_27, "cell 15 0 3 1,grow");
textField_28 = new JTextField();
textField_28.setText("Total Price");
textField_28.setFont(new Font("Tahoma", Font.PLAIN, 32));
textField_28.setEditable(false);
textField_28.setColumns(10);
frame.getContentPane().add(textField_28, "cell 19 0 3 1,alignx left,growy");
btnNewButton_1 = new JButton("Calculate Total");
btnNewButton_1.setFont(new Font("Tahoma", Font.BOLD, 36));
frame.getContentPane().add(btnNewButton_1, "cell 10 14 3 3,alignx left,growy");
textField_43 = new JTextField();
textField_43.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_43.setColumns(10);
frame.getContentPane().add(textField_43, "cell 17 14 3 1,grow");
txtPriceReduction = new JTextField();
txtPriceReduction.setEditable(false);
txtPriceReduction.setFont(new Font("Tahoma", Font.PLAIN, 27));
txtPriceReduction.setText("Price Reduction (%)");
frame.getContentPane().add(txtPriceReduction, "cell 13 14 3 1,grow");
txtPriceReduction.setColumns(10);
textField_44 = new JTextField();
textField_44.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_44.setEditable(false);
textField_44.setColumns(10);
frame.getContentPane().add(textField_44, "cell 2 10,grow");
textField_45 = new JTextField();
textField_45.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_45.setEditable(false);
textField_45.setColumns(10);
frame.getContentPane().add(textField_45, "cell 12 10,growx,aligny top");
btnNewButton_2 = new JButton("Calculate");
btnNewButton_2.setFont(new Font("Tahoma", Font.BOLD, 30));
frame.getContentPane().add(btnNewButton_2, "cell 21 14,grow");
textField_46 = new JTextField();
textField_46.setFont(new Font("Tahoma", Font.PLAIN, 34));
textField_46.setEditable(false);
textField_46.setColumns(10);
frame.getContentPane().add(textField_46, "cell 17 16 3 1,grow");
btnNewButton.addActionListener(new Action1());
btnNewButton_1.addActionListener(new Action2());
btnNewButton_2.addActionListener(new Action3());
}
static class Action1 implements ActionListener{
public void actionPerformed(ActionEvent e){
// Total # of pairs per glove
double LA = 0;
double LB = 0;
double SA = 0;
double SB = 0;
double total = 0;
// Percentage of gloves compared to total
double percLA = 0;
double percLB = 0;
double percSA = 0;
double percSB = 0;
double percTotal = 0;
// Price per glove type
double priceLA = 0;
double priceLB = 0;
double priceSA = 0;
double priceSB = 0;
// Sets price totals
double totalLA = 0;
double totalLB = 0;
double totalSA = 0;
double totalSB = 0;
double grandTotal = 0;
// Calculates value for total prices
// Sets formats for % and $
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
NumberFormat normal = NumberFormat.getNumberInstance();
// Sets value for total # pairs per glove
LA = Double.parseDouble(textField_1.getText());
LB = Double.parseDouble(textField_9.getText());
SA = Double.parseDouble(textField_13.getText());
SB = Double.parseDouble(textField_17.getText());
total = LA + LB + SA + SB;
textField_44.setText(normal.format(total));
// Sets value for percentage (of gloves to total)
percLA = LA / total;
percLB = LB / total;
percSA = SA / total;
percSB = SB / total;
percTotal = percLA + percLB + percSA + percSB;
textField_2.setText(percentFormat.format(percLA));
textField_10.setText(percentFormat.format(percLB));
textField_14.setText(percentFormat.format(percSA));
textField_18.setText(percentFormat.format(percSB));
// Grabs value for price per pair
priceLA = Double.parseDouble(textField_3.getText());
priceLB = Double.parseDouble(textField_12.getText());
priceSA = Double.parseDouble(textField_15.getText());
priceSB = Double.parseDouble(textField_19.getText());
// Sets value for total (price)
totalLA = LA * priceLA;
totalLB = LB * priceLB;
totalSA = SA * priceSA;
totalSB = SB * priceSB;
grandTotal = totalLA + totalLB + totalSA + totalSB;
textField_4.setText(dollarFormat.format(totalLA));
textField_11.setText(dollarFormat.format(totalLB));
textField_16.setText(dollarFormat.format(totalSA));
textField_20.setText(dollarFormat.format(totalSB));
textField_23.setText(dollarFormat.format(grandTotal));
// Sets value for chart #2's glove names
textField.setText(txtLatexA.getText());
textField_5.setText(txtLatexB.getText());
textField_6.setText(txtSyntheticA.getText());
textField_7.setText(txtSyntheticB.getText());
// Sets # of gloves per type
textField_8.setText(textField_1.getText());
textField_21.setText(textField_9.getText());
textField_22.setText(textField_13.getText());
textField_24.setText(textField_17.getText());
textField_45.setText(textField_44.getText());
//29,30,31,32
textField_29.setText(textField_2.getText());
textField_30.setText(textField_10.getText());
textField_31.setText(textField_14.getText());
textField_32.setText(textField_18.getText());
//33,34,35,36
textField_33.setText(dollarFormat.format(priceLA));
textField_34.setText(dollarFormat.format(priceLB));
textField_35.setText(dollarFormat.format(priceSA));
textField_36.setText(dollarFormat.format(priceSB));
//37,38,39,40,42
textField_37.setText(dollarFormat.format(totalLA));
textField_38.setText(dollarFormat.format(totalLB));
textField_39.setText(dollarFormat.format(totalSA));
textField_40.setText(dollarFormat.format(totalSB));
textField_42.setText(dollarFormat.format(grandTotal));
textField_41.setText(dollarFormat.format(grandTotal));
}
}
static class Action2 implements ActionListener{
public void actionPerformed(ActionEvent e){
// Total # of pairs per glove
double LA = 0;
double LB = 0;
double SA = 0;
double SB = 0;
double total = 0;
// Percentage of gloves compared to total
double percLA = 0;
double percLB = 0;
double percSA = 0;
double percSB = 0;
double percTotal = 0;
// Price per glove type
double priceLA = 0;
double priceLB = 0;
double priceSA = 0;
double priceSB = 0;
// Sets price totals
double totalLA = 0;
double totalLB = 0;
double totalSA = 0;
double totalSB = 0;
double grandTotal = 0;
// Sets formats for % and $
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
NumberFormat normal = NumberFormat.getNumberInstance();
// Sets value for total # pairs per glove
LA = Double.parseDouble(textField_8.getText());
LB = Double.parseDouble(textField_21.getText());
SA = Double.parseDouble(textField_22.getText());
SB = Double.parseDouble(textField_24.getText());
total = LA + LB + SA + SB;
// Sets value for percentage (of gloves to total)
percLA = LA / total;
percLB = LB / total;
percSA = SA / total;
percSB = SB / total;
percTotal = percLA + percLB + percSA + percSB;
textField_29.setText(percentFormat.format(percLA));
textField_30.setText(percentFormat.format(percLB));
textField_31.setText(percentFormat.format(percSA));
textField_32.setText(percentFormat.format(percSB));
// Grabs value for price per pair
priceLA = Double.parseDouble(textField_3.getText());
priceLB = Double.parseDouble(textField_12.getText());
priceSA = Double.parseDouble(textField_15.getText());
priceSB = Double.parseDouble(textField_19.getText());
// Sets value for total (price)
totalLA = LA * priceLA;
totalLB = LB * priceLB;
totalSA = SA * priceSA;
totalSB = SB * priceSB;
grandTotal = totalLA + totalLB + totalSA + totalSB;
textField_37.setText(dollarFormat.format(totalLA));
textField_38.setText(dollarFormat.format(totalLB));
textField_39.setText(dollarFormat.format(totalSA));
textField_40.setText(dollarFormat.format(totalSB));
textField_41.setText(dollarFormat.format(grandTotal));
textField_42.setText(dollarFormat.format(grandTotal));
}
}
static class Action3 implements ActionListener{
public void actionPerformed(ActionEvent e){
// Total # of pairs per glove
double LA = 0;
double LB = 0;
double SA = 0;
double SB = 0;
double total = 0;
// User input for percentage reduction
double userAmex = 0;
double percentage = 0;
double newTotal = 0;
// Percentage of gloves compared to total
double percLA = 0;
double percLB = 0;
double percSA = 0;
double percSB = 0;
double percTotal = 0;
// Price per glove type
double priceLA = 0;
double priceLB = 0;
double priceSA = 0;
double priceSB = 0;
// Sets price totals
double totalLA = 0;
double totalLB = 0;
double totalSA = 0;
double totalSB = 0;
double grandTotal = 0;
// Sets formats for % and $
NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
NumberFormat normal = NumberFormat.getNumberInstance();
// Sets value for total # pairs per glove
LA = Double.parseDouble(textField_1.getText());
LB = Double.parseDouble(textField_9.getText());
SA = Double.parseDouble(textField_13.getText());
SB = Double.parseDouble(textField_17.getText());
total = LA + LB + SA + SB;
// Sets value for percentage (of gloves to total)
percLA = LA / total;
percLB = LB / total;
percSA = SA / total;
percSB = SB / total;
percTotal = percLA + percLB + percSA + percSB;
// Grabs value for price per pair
priceLA = Double.parseDouble(textField_3.getText());
priceLB = Double.parseDouble(textField_12.getText());
priceSA = Double.parseDouble(textField_15.getText());
priceSB = Double.parseDouble(textField_19.getText());
// Sets value for total (price)
totalLA = LA * priceLA;
totalLB = LB * priceLB;
totalSA = SA * priceSA;
totalSB = SB * priceSB;
grandTotal = totalLA + totalLB + totalSA + totalSB;
userAmex = Double.parseDouble(textField_43.getText());
percentage = userAmex / 100;
newTotal = grandTotal - (grandTotal * percentage);
textField_46.setText(dollarFormat.format(newTotal));
}
}
}
答案 0 :(得分:1)
首先,您需要根据屏幕大小调整JFrame的大小:
final Dimension screenDimensions = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(
(int) (screenDimensions.width * 0.05), (int) (screenDimensions.height * 0.05),
(int) (screenDimensions.width * 0.9), (int) (screenDimensions.height * 0.9));
JFrame的内容也应根据相对屏幕尺寸进行缩放。
您还应该认真考虑使用XML文件来包含UI元素以减少代码的大小,请参阅https://eclipse.org/windowbuilder/