かなり初歩的な質問で申し訳ございません。
急遽仕事でJavaを扱う事になりまして分からない事がございます。
開始ボタンをクリックすると最終的にtest()メソッドが実行されるコードです。
生成されたlabel_27の文字100円を、OrderThreadにあるtest()メソッドの処理で1000円に書き換えたいと思っております。
ただあまり詳しくないため方法が調べたのですが良く分かりませんでした。
お手数すいませんが、どのようなコードを書けばいいのか教えて頂けますと幸いです。
よろしくお願い申し上げます。
Java
1public class Scene { 2 private OrderThread _thread = null; 3 private JFrame frame; 4 5 // 開始 6 public static void main(String[] args) { 7 EventQueue.invokeLater(new Runnable() { 8 public void run() { 9 Scene window = new Scene(); 10 window.frame.setVisible(true); 11 } 12 }); 13 } 14 15 // フォーム 16 public Scene() { 17 frame = new JFrame("テスト"); 18 frame.setBounds(100, 100, 1000, 500); 19 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 20 frame.getContentPane().setLayout(null); 21 22 JPanel start_stop = new JPanel(); 23 start_stop.setBorder(new LineBorder(Color.LIGHT_GRAY)); 24 frame.getContentPane().add(start_stop); 25 start_stop.setLayout(null); 26 27 JButton btnNewButton = new JButton("開始"); 28 btnNewButton.addActionListener(new ActionListener() { 29 public void actionPerformed(ActionEvent e) { 30 _thread = new OrderThread(); 31 _thread.start(); 32 } 33 }); 34 start_stop.add(btnNewButton); 35 36 JPanel balance = new JPanel(); 37 balance.setLayout(null); 38 balance.setBorder(new LineBorder(Color.LIGHT_GRAY)); 39 frame.getContentPane().add(balance); 40 41 //下記の1000円の文字を10000円に変更したい 42 JLabel label_27 = new JLabel("1000円"); 43 balance.add(label_27); 44 } 45 46 //実行スレッド 47 private class OrderThread extends Thread { 48 public void run() { 49 //メソッド実行 50 test(); 51 } 52 53 private boolean test() throws InterruptedException { 54 /* 55 public Scene()にあるlabel_27の文字を変更する処理 56 */ 57 return true; 58 } 59 } 60}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/20 23:14