|
|
@@ -100,8 +100,40 @@ public class MesClient extends JFrame {
|
|
|
public static boolean timer_flag = false; // 开始计时标志 false=非工作开始计时 true=工件开始计时
|
|
|
public static long timer_nums = 0; // 秒数
|
|
|
|
|
|
- public static JButton[] weldButtons = new JButton[32]; // 存储按钮对象
|
|
|
- public static boolean[] weldClickStates = new boolean[32]; // 存储点击状态
|
|
|
+ // 与图纸一致的焊缝编号(含 16-1、70-1 等子序号)
|
|
|
+ public static final String[] WELD_LABELS = {
|
|
|
+ "1", "2",
|
|
|
+ "3-1", "3-2", "3-3", "3-4", "3-5",
|
|
|
+ "4-1", "4-2", "4-3", "4-4", "4-5",
|
|
|
+ "5-1", "5-2", "5-3", "5-4", "5-5",
|
|
|
+ "6", "7", "8", "9", "10", "11", "12", "13",
|
|
|
+ "14-1", "14-2", "14-3", "14-4",
|
|
|
+ "15-1", "15-2", "15-3", "15-4", "15-5", "15-6",
|
|
|
+ "16-1", "16-2", "16-3", "16-4", "16-5",
|
|
|
+ "17", "18", "19", "20", "21", "22", "23", "24",
|
|
|
+ "25", "26", "27", "28", "29", "30", "31", "32", "33",
|
|
|
+ "34-1", "34-2", "35-1", "35-2",
|
|
|
+ "36", "37", "38", "39", "40", "41", "42", "43", "44",
|
|
|
+ "45", "46", "47", "48", "49", "50", "51", "52",
|
|
|
+ "53", "54", "55", "56", "57", "58", "59", "60", "61", "62",
|
|
|
+ "63-1", "63-2", "64-1", "64-2",
|
|
|
+ "65", "66", "67", "68", "69",
|
|
|
+ "70-1", "70-2", "70-3", "70-4", "70-5",
|
|
|
+ "71-1", "71-2", "71-3", "71-4", "71-5",
|
|
|
+ "72", "73", "74", "75", "76", "77", "78", "79", "80",
|
|
|
+ "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
|
|
|
+ "91-1", "91-2", "91-3", "91-4", "91-5", "91-6",
|
|
|
+ "92-1", "92-2", "92-3", "92-4", "92-5", "92-6",
|
|
|
+ "93-1", "93-2", "93-3", "93-4", "93-5", "93-6",
|
|
|
+ "94-1", "94-2", "95-1", "95-2",
|
|
|
+ "96-1", "96-2", "96-3", "96-4", "96-5", "96-6",
|
|
|
+ "97-1", "97-2", "97-3", "97-4", "97-5", "97-6",
|
|
|
+ "98-1", "98-2", "98-3", "98-4", "98-5", "98-6",
|
|
|
+ "99", "100", "101-1", "101-2", "102", "103", "104-1", "104-2",
|
|
|
+ "105-1", "105-2", "106", "107", "108", "109"
|
|
|
+ };
|
|
|
+ public static JButton[] weldButtons = new JButton[WELD_LABELS.length];
|
|
|
+ public static boolean[] weldClickStates = new boolean[WELD_LABELS.length];
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
@@ -487,21 +519,21 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
tabbedPane.setMinimumSize(new Dimension(400, 50));
|
|
|
- tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
|
|
|
+ tabbedPane.setFont(new Font("宋体", Font.BOLD, 15));
|
|
|
contentPane.add(tabbedPane);
|
|
|
|
|
|
- //首页
|
|
|
+ // ==================== 工作面板(单页,含全部焊缝编号) ====================
|
|
|
JPanel indexPanelA = new JPanel();
|
|
|
indexScrollPaneA = new JScrollPane(indexPanelA);
|
|
|
- indexPanelA.setLayout(null);
|
|
|
+ indexPanelA.setLayout(new BorderLayout(10, 10));
|
|
|
|
|
|
- product_sn = new JTextField();
|
|
|
+ JPanel scanRow = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));
|
|
|
+ product_sn = new JTextField(30);
|
|
|
product_sn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
product_sn.setEditable(false);
|
|
|
product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- product_sn.setBounds(81, 40, 602, 70);
|
|
|
- indexPanelA.add(product_sn);
|
|
|
- product_sn.setColumns(10);
|
|
|
+ product_sn.setPreferredSize(new Dimension(600, 70));
|
|
|
+ scanRow.add(product_sn);
|
|
|
|
|
|
f_scan_data_bt_1 = new JButton("扫码");
|
|
|
f_scan_data_bt_1.addActionListener(new ActionListener() {
|
|
|
@@ -512,52 +544,38 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- f_scan_data_bt_1.setBounds(693, 40, 198, 70);
|
|
|
- indexPanelA.add(f_scan_data_bt_1);
|
|
|
+ f_scan_data_bt_1.setPreferredSize(new Dimension(198, 70));
|
|
|
+ scanRow.add(f_scan_data_bt_1);
|
|
|
|
|
|
+ indexPanelA.add(scanRow, BorderLayout.NORTH);
|
|
|
|
|
|
- // 创建一个面板来容纳按钮,使用网格布局 (4行8列)
|
|
|
- JPanel weldPanel = new JPanel();
|
|
|
- weldPanel.setBounds(81, 130, 810, 238); // 位置在扫码框下方,高度200
|
|
|
- weldPanel.setLayout(new GridLayout(4, 8, 10, 10)); // 4行8列,间距10
|
|
|
- weldPanel.setOpaque(false); // 背景透明以便看清底层背景图(如果有)
|
|
|
-
|
|
|
- for (int i = 0; i < weldButtons.length; i++) {
|
|
|
- int index = i; // 供内部类使用
|
|
|
- weldButtons[i] = new JButton("焊缝" + (i + 1));
|
|
|
- weldButtons[i].setFont(new Font("微软雅黑", Font.PLAIN, 18)); // 字体稍小以适应密集排列
|
|
|
- weldButtons[i].setEnabled(false); // 初始时禁用按钮
|
|
|
- // 添加点击事件
|
|
|
- weldButtons[i].addActionListener(new ActionListener() {
|
|
|
- @Override
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- JButton btn = (JButton) e.getSource();
|
|
|
- //判断是否选中
|
|
|
- if (weldClickStates[index]) {
|
|
|
- // 当前是绿色(已选中) -> 再次点击变为未选中
|
|
|
- btn.setBackground(null); // 恢复默认颜色
|
|
|
- weldClickStates[index] = false;
|
|
|
- log.info("已取消按钮: 焊缝" + (index + 1));
|
|
|
- } else {
|
|
|
- // 当前是默认色(未选中) -> 点击变为绿色
|
|
|
- btn.setBackground(Color.GREEN);
|
|
|
- weldClickStates[index] = true;
|
|
|
- log.info("已选中按钮: 焊缝" + (index + 1));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- weldPanel.add(weldButtons[i]);
|
|
|
- }
|
|
|
- indexPanelA.add(weldPanel);
|
|
|
+ JPanel centerPanel = new JPanel();
|
|
|
+ centerPanel.setLayout(new BorderLayout(10, 10));
|
|
|
+ centerPanel.setBorder(new EmptyBorder(10, 20, 10, 20));
|
|
|
|
|
|
+ // 180 个焊缝按钮,滚动查看;文案与图纸编号一致(如 16-1)
|
|
|
+ JPanel weldPanel = new JPanel();
|
|
|
+ weldPanel.setLayout(new GridLayout(0, 10, 6, 6));
|
|
|
+ weldPanel.setOpaque(false);
|
|
|
+ addWeldButtonsToPanel(weldPanel, 0, WELD_LABELS.length);
|
|
|
+ JScrollPane weldScroll = new JScrollPane(weldPanel);
|
|
|
+ weldScroll.setBorder(null);
|
|
|
+ weldScroll.getVerticalScrollBar().setUnitIncrement(16);
|
|
|
+ centerPanel.add(weldScroll, BorderLayout.CENTER);
|
|
|
|
|
|
fxlabel = new JLabel("该工件为返修件,请仔细检查");
|
|
|
fxlabel.setFont(new Font("微软雅黑", Font.PLAIN, 38));
|
|
|
- fxlabel.setBounds(81, 380, 810, 70);
|
|
|
fxlabel.setForeground(Color.RED);
|
|
|
fxlabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
+ fxlabel.setPreferredSize(new Dimension(810, 70));
|
|
|
fxlabel.setVisible(false);
|
|
|
- indexPanelA.add(fxlabel);
|
|
|
+ centerPanel.add(fxlabel, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ indexPanelA.add(centerPanel, BorderLayout.CENTER);
|
|
|
+
|
|
|
+ JPanel bottomPanel = new JPanel();
|
|
|
+ bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
|
|
|
+ bottomPanel.setBorder(new EmptyBorder(10, 10, 20, 10));
|
|
|
|
|
|
finish_ok_bt = new JButton("OK");
|
|
|
finish_ok_bt.setEnabled(false);
|
|
|
@@ -569,11 +587,6 @@ public class MesClient extends JFrame {
|
|
|
MesClient.setMenuStatus("工件码为空,请重试",-1);
|
|
|
return;
|
|
|
}
|
|
|
- // 去掉焊道选择的阻拦检查,允许选择焊道后点击OK
|
|
|
- // if(!getWeldTrueIndexes().isEmpty()){
|
|
|
- // MesClient.setMenuStatus("提交漏点,请点NG",-1);
|
|
|
- // return;
|
|
|
- // }
|
|
|
getUser();
|
|
|
|
|
|
String result = "OK";
|
|
|
@@ -592,16 +605,15 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
|
|
|
finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- finish_ok_bt.setBounds(185, 460, 240, 80);
|
|
|
+ finish_ok_bt.setPreferredSize(new Dimension(240, 80));
|
|
|
finish_ok_bt.setEnabled(false);
|
|
|
- indexPanelA.add(finish_ok_bt);
|
|
|
+ bottomPanel.add(finish_ok_bt);
|
|
|
|
|
|
finish_ng_bt = new JButton("NG");
|
|
|
finish_ng_bt.setEnabled(false);
|
|
|
finish_ng_bt.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
if(work_status == 1 && check_quality_result){
|
|
|
-
|
|
|
String sn = getBarcode(product_sn.getText());
|
|
|
if(sn.isEmpty()){
|
|
|
MesClient.setMenuStatus("工件码为空,请重试",-1);
|
|
|
@@ -628,45 +640,33 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
|
|
|
finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
- finish_ng_bt.setBounds(508, 460, 240, 80);
|
|
|
+ finish_ng_bt.setPreferredSize(new Dimension(240, 80));
|
|
|
finish_ng_bt.setEnabled(false);
|
|
|
- indexPanelA.add(finish_ng_bt);
|
|
|
+ bottomPanel.add(finish_ng_bt);
|
|
|
+
|
|
|
+ indexPanelA.add(bottomPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
tabbedPane.setEnabledAt(0, true);
|
|
|
|
|
|
-// searchScrollPane = new JScrollPane((Component) null);
|
|
|
-
|
|
|
indexPanelC = new JPanel();
|
|
|
searchScrollPaneDj = new JScrollPane(indexPanelC);
|
|
|
indexPanelC.setLayout(null);
|
|
|
|
|
|
tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
|
|
|
|
|
|
-
|
|
|
- // ========== 工作记录 Tab(改造:当前工位Tab + 所有工位Tab) ==========
|
|
|
- // 旧代码已注释:
|
|
|
- // indexPanelB = new JPanel();
|
|
|
- // searchScrollPane = new JScrollPane(indexPanelB);
|
|
|
- // indexPanelB.setLayout(null);
|
|
|
- // tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
|
|
|
-
|
|
|
- // 创建工作记录的子 TabbedPane
|
|
|
+ // ========== 工作记录 Tab(当前工位 + 所有工位) ==========
|
|
|
JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
|
- // OP80 工位:当前工位 + 所有工位
|
|
|
WorkRecordPanel[] workRecordPanels = new WorkRecordPanel[2];
|
|
|
|
|
|
- // 当前工位Tab(使用配置文件中的 mes.gw)
|
|
|
workRecordPanels[0] = new WorkRecordPanel(mes_gw, mes_line_sn);
|
|
|
workRecordTabbedPane.addTab(mes_gw, null, workRecordPanels[0], "查询" + mes_gw + "的工作记录");
|
|
|
|
|
|
- // 所有工位Tab(查询整条产线所有工位)
|
|
|
workRecordPanels[1] = new WorkRecordPanel(null, mes_line_sn);
|
|
|
workRecordTabbedPane.addTab("所有工位", null, workRecordPanels[1], "查询整条产线所有工位的工作记录");
|
|
|
|
|
|
- // 切换子Tab时自动刷新数据
|
|
|
workRecordTabbedPane.addChangeListener(e -> {
|
|
|
int selectedIdx = workRecordTabbedPane.getSelectedIndex();
|
|
|
if (selectedIdx >= 0 && selectedIdx < workRecordPanels.length) {
|
|
|
@@ -674,30 +674,30 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 将子 TabbedPane 添加到主 TabbedPane
|
|
|
tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), workRecordTabbedPane, null);
|
|
|
|
|
|
- tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
+ tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
@Override
|
|
|
public void stateChanged(ChangeEvent e) {
|
|
|
JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
|
|
|
int selectedIndex = tabbedPane.getSelectedIndex();
|
|
|
System.out.println("selectedIndex:"+selectedIndex);
|
|
|
-
|
|
|
- if(selectedIndex == 1){
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- ImagePanel hfPanel = new ImagePanel("/bg/mes_hf.png");
|
|
|
-
|
|
|
- // 设置背景色(可选,比如设置为白色或灰色背景)
|
|
|
- hfPanel.setBackground(Color.WHITE);
|
|
|
-
|
|
|
- // 添加到 TabbedPane
|
|
|
- // 第二个参数是图标,这里复用了 menu_data_preprocess.png,您也可以换成其他图标
|
|
|
- tabbedPane.addTab("查看焊缝", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), hfPanel, "查看焊缝图片");
|
|
|
+ // 三张焊缝图各占一页,按窗口等比缩放(不滚动)
|
|
|
+ ImagePanel hfPanel1 = new ImagePanel("/bg/hf_1_69.png");
|
|
|
+ hfPanel1.setBackground(Color.WHITE);
|
|
|
+ tabbedPane.addTab("查看焊缝1-69", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")),
|
|
|
+ hfPanel1, "焊缝1到69");
|
|
|
+ ImagePanel hfPanel2 = new ImagePanel("/bg/hf_70_90.png");
|
|
|
+ hfPanel2.setBackground(Color.WHITE);
|
|
|
+ tabbedPane.addTab("查看焊缝70-90", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")),
|
|
|
+ hfPanel2, "焊缝70到90");
|
|
|
+ ImagePanel hfPanel3 = new ImagePanel("/bg/hf_91_109.png");
|
|
|
+ hfPanel3.setBackground(Color.WHITE);
|
|
|
+ tabbedPane.addTab("查看焊缝91-109", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")),
|
|
|
+ hfPanel3, "焊缝91到109");
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -885,7 +885,9 @@ public class MesClient extends JFrame {
|
|
|
//开启焊缝按钮
|
|
|
public static void startWeldButton(){
|
|
|
for (int i = 0; i < weldButtons.length; i++) {
|
|
|
- weldButtons[i].setEnabled(true);
|
|
|
+ if (weldButtons[i] != null) {
|
|
|
+ weldButtons[i].setEnabled(true);
|
|
|
+ }
|
|
|
weldClickStates[i] = false; // 重置状态
|
|
|
}
|
|
|
}
|
|
|
@@ -894,37 +896,70 @@ public class MesClient extends JFrame {
|
|
|
public static void closeWeldButton(){
|
|
|
for (int i = 0; i < weldButtons.length; i++) {
|
|
|
weldClickStates[i] = false; // 重置状态
|
|
|
- weldButtons[i].setBackground(null); // 重置颜色
|
|
|
- weldButtons[i].setEnabled(false);
|
|
|
+ if (weldButtons[i] != null) {
|
|
|
+ weldButtons[i].setBackground(null); // 重置颜色
|
|
|
+ weldButtons[i].setEnabled(false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //获取按钮下标
|
|
|
+ // 获取已选焊缝编号(与图纸一致,如 16-1,70-2)
|
|
|
public static String getWeldTrueIndexes() {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
boolean first = true;
|
|
|
|
|
|
for (int i = 0; i < weldClickStates.length; i++) {
|
|
|
- // 直接判断布尔值
|
|
|
if (weldClickStates[i]) {
|
|
|
if (!first) {
|
|
|
sb.append(",");
|
|
|
}
|
|
|
- sb.append(i+1);
|
|
|
+ sb.append(WELD_LABELS[i]);
|
|
|
first = false;
|
|
|
}
|
|
|
}
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量添加焊缝按钮到指定面板,文案使用 WELD_LABELS
|
|
|
+ */
|
|
|
+ private void addWeldButtonsToPanel(JPanel panel, int start, int end) {
|
|
|
+ for (int i = start; i < end; i++) {
|
|
|
+ if (i >= weldButtons.length) break;
|
|
|
+ int index = i;
|
|
|
+ String label = WELD_LABELS[i];
|
|
|
+
|
|
|
+ weldButtons[i] = new JButton(label);
|
|
|
+ weldButtons[i].setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
|
|
+ weldButtons[i].setEnabled(false);
|
|
|
+ weldButtons[i].setToolTipText("焊缝" + label);
|
|
|
|
|
|
+ weldButtons[i].addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ JButton btn = (JButton) e.getSource();
|
|
|
+ if (weldClickStates[index]) {
|
|
|
+ btn.setBackground(null);
|
|
|
+ weldClickStates[index] = false;
|
|
|
+ log.info("已取消按钮: 焊缝" + label);
|
|
|
+ } else {
|
|
|
+ btn.setBackground(Color.GREEN);
|
|
|
+ weldClickStates[index] = true;
|
|
|
+ log.info("已选中按钮: 焊缝" + label);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ panel.add(weldButtons[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 自定义面板,用于同比例缩放显示图片
|
|
|
+ /**
|
|
|
+ * 焊缝图面板:按窗口等比缩小居中显示,不滚动
|
|
|
+ */
|
|
|
public class ImagePanel extends JPanel {
|
|
|
private Image image;
|
|
|
|
|
|
public ImagePanel(String imagePath) {
|
|
|
- // 加载图片资源
|
|
|
try {
|
|
|
ImageIcon icon = new ImageIcon(MesClient.class.getResource(imagePath));
|
|
|
this.image = icon.getImage();
|
|
|
@@ -936,33 +971,26 @@ public class MesClient extends JFrame {
|
|
|
@Override
|
|
|
protected void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
- if (image != null) {
|
|
|
- // 获取面板的宽高
|
|
|
- int panelWidth = getWidth();
|
|
|
- int panelHeight = getHeight();
|
|
|
-
|
|
|
- // 获取图片的原始宽高
|
|
|
- int imageWidth = image.getWidth(this);
|
|
|
- int imageHeight = image.getHeight(this);
|
|
|
-
|
|
|
- if (imageWidth > 0 && imageHeight > 0) {
|
|
|
- // 计算缩放比例,保持长宽比
|
|
|
- double widthRatio = (double) panelWidth / imageWidth;
|
|
|
- double heightRatio = (double) panelHeight / imageHeight;
|
|
|
- double ratio = Math.min(widthRatio, heightRatio);
|
|
|
-
|
|
|
- // 计算新的绘制宽高
|
|
|
- int newWidth = (int) (imageWidth * ratio);
|
|
|
- int newHeight = (int) (imageHeight * ratio);
|
|
|
-
|
|
|
- // 计算居中位置
|
|
|
- int x = (panelWidth - newWidth) / 2;
|
|
|
- int y = (panelHeight - newHeight) / 2;
|
|
|
-
|
|
|
- // 绘制缩放后的图片
|
|
|
- g.drawImage(image, x, y, newWidth, newHeight, this);
|
|
|
- }
|
|
|
+ if (image == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int panelWidth = getWidth();
|
|
|
+ int panelHeight = getHeight();
|
|
|
+ int imageWidth = image.getWidth(this);
|
|
|
+ int imageHeight = image.getHeight(this);
|
|
|
+ if (imageWidth <= 0 || imageHeight <= 0 || panelWidth <= 0 || panelHeight <= 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ double ratio = Math.min((double) panelWidth / imageWidth, (double) panelHeight / imageHeight);
|
|
|
+ int newWidth = (int) (imageWidth * ratio);
|
|
|
+ int newHeight = (int) (imageHeight * ratio);
|
|
|
+ int x = (panelWidth - newWidth) / 2;
|
|
|
+ int y = (panelHeight - newHeight) / 2;
|
|
|
+ Graphics2D g2 = (Graphics2D) g.create();
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g2.drawImage(image, x, y, newWidth, newHeight, this);
|
|
|
+ g2.dispose();
|
|
|
}
|
|
|
}
|
|
|
|