質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

0回答

1361閲覧

ActionListenerの実装

o2ka_cz

総合スコア13

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2019/05/06 14:57

添付した画像のような画面を実装したい

各ボタンを押すと、選択したデータを格納、データをソート、データをリセットするようにしたい。

発生している問題

ActionPerformedメソッドの実装方法がわからない。

該当のソースコード

Java
import java.util.;
import java.awt.
;
import java.awt.event.;
import javax.swing.
;
import javax.swing.event.*;

class SortableDataStore implements Comparable<SortableDataStore>{
protected String productItem, noItem, orderInfo;
public SortableDataStore(String[] data) {

}
public SortableDataStore(String p, String n, String o) {
productItem = p;
noItem = n;
orderInfo = o;
}
public String toString() {

return new String(productItem + ", " + noItem + ", " + orderInfo) ;

}

// fill in the area to implement Comparable interface
}

public class ProductOrder extends JFrame implements ActionListener{
protected String list_Contents, noOrder, orderInfo;
protected SortableDataStore[] v = new SortableDataStore[20];

protected JPanel topp, leftp, rightp,bottomp,centerup, centerdown;
protected JButton putb, showb, sortb, clearb;
protected JLabel title, noorder, orderinfo;
protected JList plist;
protected JTextField nofield, infofield;
protected JTextArea contentsarea;
protected String[] data = {"IBM NoteBook", "Dell Product", "MS Windows", "Sun Workstation", "Oracle DB", "MySQL"};
protected int idx = 0;
protected int lastIndex = -1;

public ProductOrder() {
getContentPane().setLayout(new BorderLayout());
topp = new JPanel();
leftp = new JPanel();
rightp = new JPanel();
bottomp = new JPanel();
centerup = new JPanel();
centerdown = new JPanel();

getContentPane().add(topp, "North"); getContentPane().add(leftp, "West"); getContentPane().add(rightp, "Center"); getContentPane().add(bottomp, "South"); title = new JLabel("Product Order"); title.setFont(new Font("Product Order",Font.BOLD, 20)); topp.add(title); plist = new JList(data); plist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); plist.addListSelectionListener(new ProductItemListener()); leftp.add(plist); noorder = new JLabel("No. of Order Items"); orderinfo = new JLabel("Order Information"); nofield = new JTextField(); infofield = new JTextField(); putb = new JButton("Put into Cart"); putb.addActionListener(new PutButtonListener()); sortb = new JButton("Sort Items"); sortb.addActionListener(new SortButtonListener()); clearb = new JButton("Reset Cart"); clearb.addActionListener(new ResetButtonListener()); centerup.setLayout(new GridLayout(2,2)); centerup.add(noorder); centerup.add(orderinfo); centerup.add(nofield); centerup.add(infofield); centerdown.setLayout(new GridLayout(1,2)); centerdown.add(putb); centerdown.add(sortb); centerdown.add(clearb); rightp.setLayout(new GridLayout(2,1)); rightp.add(centerup); rightp.add(centerdown); showb = new JButton("Show Cart"); showb.addActionListener(new ShowButtonListener()); contentsarea = new JTextArea(10,1); bottomp.setLayout(new GridLayout(1,2)); bottomp.add(showb); bottomp.add(contentsarea);

} // Product Order constructor

//event listeners.
//inner classes for the listeners.
public void actionPerformed(ActionEvent e) {
//Object o = e.getSource();
}

public static void main (String args[]) {
ProductOrder f = new ProductOrder();
f.setTitle("Product Order");
f.setSize(500,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
} // end of ProductOrder

試したこと

Object o = e.getSource();などのようにして、オブジェクトで何を実行するかを判断してみた。

イメージ説明

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jimbe

2019/05/06 19:03 編集

先ず, コードは専用の記法があります. コードの上下を「```」の行で囲むと薄いグレーの枠内に表示され, インデントがきちんと表示されたりしますので, 修正して頂けますか. そして, 各ボタンに addActionListener されているクラスのコードもご提示願えますか.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問