Javaの道 Javaに関する
 ニュースJava基本Servlet・JSPオープンソースFAQ掲示板
Javaの道 >  掲示板 >  掲示板(Printerjobのダイアログが出現するまでの時間短縮するには?)
閲覧数:378
掲示板(Printerjobのダイアログが出現するまでの時間短縮するには?)
名前
題名 Printerjobのダイアログが出現するまでの時間短縮するには?
質問内容

質問を評価する
(0ポイント)
//印刷ボタン
    private JButton getJButton0() {
        if (jButton0 == null) {
            jButton0 = new JButton();
            //ボタンの各印刷文字は各
PreviewPにて指定するので、ここでは空欄のまま
            jButton0.setText("");
            
jButton0.setFont(getcellFontSize28());
            //ボタンクリック時のリスナ

            
jButton0.addActionListener(new ActionListener()    {
                public void 
actionPerformed(ActionEvent e) {
                    //ボタンク
リック効果音を鳴らす
                    
btnSound.play();
                    //ボックス
スコアパネルをnew
                    
bsprintPanel = new BoxScorePanel();
                    //スコアシ
ートパネルをnew
                    
ssprintPanel = new ScoreSheetPanel();
                    //
                    attributes 
= new HashPrintRequestAttributeSet();
                    
                    if 
(e.getActionCommand().equals("ボックススコア印
刷")) {
                        
try {
                            
PrinterJob printjob1 = PrinterJob.getPrinterJob();
                            
                            
printjob1.setPrintable(bsprintPanel);
                            
                            
if (printjob1.printDialog(attributes)) {
                                
printjob1.print(attributes);
                            
}
                        } 
catch (PrinterException exception) {
                            
JOptionPane.showMessageDialog(SheetDisplayTool.thi
s, exception);
                        }                
                    } else if 
(e.getActionCommand().equals("スコアシート印刷")) 
{
                        
try {
                            
PrinterJob printjob2 = PrinterJob.getPrinterJob();
                                                        
                            
printjob2.setPrintable(ssprintPanel);
                            
                            
if (printjob2.printDialog(attributes)) {
                                
printjob2.print(attributes);
                            
}
                        } 
catch (PrinterException exception) {
                            
JOptionPane.showMessageDialog(SheetDisplayTool.thi
s, exception);
                        }
                    }
                    //印刷ダイ
アログの「印刷ボタン」&「取り消しボタン」をクリッ
クした場合のクリック音
                    
btnSound.play();
                }
            });
        }
        return jButton0;
    }
質問日時 2013-12-26 09:40:44
名前
回答内容

回答を評価する
(0ポイント)
その後下記のコードをif文の前に配置したことで印刷ダイ
アログが出る時間が約2秒から約1秒に短縮出来ましたが、
この約1秒を短縮するにはどうしたら良いでしょうか?    
よろしくお願いします。

PrinterJob printjob1 = PrinterJob.getPrinterJob();
printjob1.setPrintable(bsprintPanel);
PrinterJob printjob2 = PrinterJob.getPrinterJob();
printjob2.setPrintable(ssprintPanel);
回答日時 2013-12-26 11:16:58
名前
回答内容

回答を評価する
(0ポイント)
以下のコードでボタンクリックから印刷ダイアログが表
示されるまでの時間を短縮することが出来ました。

private PrintRequestAttributeSet attributes = new 
HashPrintRequestAttributeSet();
private BoxScorePanel bsprintPanel = new 
BoxScorePanel();
private ScoreSheetPanel ssprintPanel = new 
ScoreSheetPanel();

//印刷ボタン
    private JButton getJButton0() {
        if (jButton0 == null) {
            jButton0 = new JButton();
            //ボタンの各印刷文字は各
PreviewPにて指定するので、ここでは空欄のまま
            jButton0.setText("");
            
jButton0.setFont(getcellFontSize28());
            
            //ボックススコア                                
final PrinterJob printjob1 = 
PrinterJob.getPrinterJob();            
printjob1.setPrintable(bsprintPanel);
            //スコアシート
            final PrinterJob printjob2 
= PrinterJob.getPrinterJob();            
printjob2.setPrintable(ssprintPanel);
            
            //ボタンクリック時のリスナ

            
jButton0.addActionListener(new ActionListener()    {
                public void 
actionPerformed(ActionEvent e) {
                    //ボタンク
リック効果音を鳴らす
                    
btnSound.play();
                    //もしボッ
クススコアボタンがクリックされた場合
                    if 
(e.getActionCommand().equals("ボックススコア印
刷")) {
                        
try {
                            
if (printjob1.printDialog(attributes)) {
                                
printjob1.print(attributes);
                            
}
                        } 
catch (PrinterException exception) {
                            
JOptionPane.showMessageDialog(SheetDisplayTool.thi
s, exception);
                        }
                    //もしスコ
アシートボタンがクリックされた場合
                    } else if 
(e.getActionCommand().equals("スコアシート印刷")) 
{
                        
try {
                            
if (printjob2.printDialog(attributes)) {
                                
printjob2.print(attributes);
                            
}
                        } 
catch (PrinterException exception) {
                            
JOptionPane.showMessageDialog(SheetDisplayTool.thi
s, exception);
                        }
                    }
                    //印刷ダイ
アログの「印刷ボタン」&「取り消しボタン」をクリッ
クした場合のクリック音
                    
btnSound.play();
                }
            });
        }
        return jButton0;
    }
回答日時 2013-12-26 13:36:29
回答内容を入力し、「確認」ボタンをクリックしてください。
ログインしていません。ログインしなくても回答はできますが、ログインすると、質問・回答の管理、更新があった場合のメールでの通知を受けることができます。 ユーザIDをお持ちでない方は「ID登録」からユーザIDの登録を行ってください。
氏名 匿名
回答内容
 



このページのトップへ
 ニュースJava基本Servlet・JSPオープンソースFAQ掲示板
Javaの道_CopyrightJavaの道