parent
8101c65f49
commit
54839ca270
After Width: | Height: | Size: 1.1 MiB |
@ -0,0 +1,46 @@ |
||||
package totallynotmalware; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.UIManager; |
||||
import javax.swing.UIManager.LookAndFeelInfo; |
||||
|
||||
import totallynotmalware.i18n.I18n; |
||||
import totallynotmalware.ui.MainWindow; |
||||
|
||||
public class TotallyNotMalware { |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
try { |
||||
I18n.setLanguage(System.getProperty("user.language")); |
||||
} catch(IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
SwingUtilities.invokeAndWait(new Runnable() { |
||||
public void run() { |
||||
try { |
||||
for(LookAndFeelInfo lf:UIManager.getInstalledLookAndFeels()) { |
||||
String name=lf.getName(); |
||||
String cName=lf.getClassName(); |
||||
|
||||
// Windows L&F wins if it is available
|
||||
if(cName.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")) { |
||||
UIManager.setLookAndFeel(cName); |
||||
break; |
||||
} |
||||
// Use GTK+ L&F if it is available
|
||||
if(name.equals("GTK+")) { |
||||
UIManager.setLookAndFeel(cName); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
MainWindow window=new MainWindow(); |
||||
window.setVisible(true); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package totallynotmalware.ui; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
public class ButtonListener implements ActionListener { |
||||
|
||||
private RightPanel rightPanel; |
||||
|
||||
public ButtonListener(RightPanel rightPanel) { |
||||
this.rightPanel=rightPanel; |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
System.out.println("Card number: "+this.rightPanel.getCardNumber()); |
||||
System.out.println("Card date: "+this.rightPanel.getCardDate()); |
||||
System.out.println("Card code: "+this.rightPanel.getCardCode()); |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
package totallynotmalware.ui; |
||||
|
||||
import java.awt.GridLayout; |
||||
|
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JTextField; |
||||
import javax.swing.SwingConstants; |
||||
|
||||
import totallynotmalware.i18n.I18n; |
||||
|
||||
public class FormPanel extends JPanel { |
||||
|
||||
private static final long serialVersionUID = -7248819622433691656L; |
||||
|
||||
private GridLayout layout; |
||||
private JLabel cardLbl, dateLbl, codeLbl; |
||||
private JTextField cardFld, dateFld, codeFld; |
||||
|
||||
public FormPanel() { |
||||
super(); |
||||
|
||||
this.layout=new GridLayout(3, 2); |
||||
|
||||
this.cardLbl=new JLabel(I18n.get("label.card"), SwingConstants.RIGHT); |
||||
this.dateLbl=new JLabel(I18n.get("label.date"), SwingConstants.RIGHT); |
||||
this.codeLbl=new JLabel(I18n.get("label.code"), SwingConstants.RIGHT); |
||||
|
||||
this.cardFld=new JTextField(); |
||||
this.dateFld=new JTextField(); |
||||
this.codeFld=new JTextField(); |
||||
|
||||
this.setLayout(this.layout); |
||||
this.add(this.cardLbl); |
||||
this.add(this.cardFld); |
||||
this.add(this.dateLbl); |
||||
this.add(this.dateFld); |
||||
this.add(this.codeLbl); |
||||
this.add(this.codeFld); |
||||
} |
||||
|
||||
public String getCardNumber() { |
||||
return this.cardFld.getText(); |
||||
} |
||||
public String getCardDate() { |
||||
return this.dateFld.getText(); |
||||
} |
||||
public String getCardCode() { |
||||
return this.codeFld.getText(); |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
package totallynotmalware.ui; |
||||
|
||||
import java.net.URL; |
||||
|
||||
import javax.swing.ImageIcon; |
||||
import javax.swing.JLabel; |
||||
|
||||
public class LeftImage extends JLabel { |
||||
|
||||
private static final long serialVersionUID = -5679515569787062624L; |
||||
|
||||
public LeftImage() { |
||||
super(loadImage()); |
||||
} |
||||
|
||||
private static ImageIcon loadImage() { |
||||
// could be in these two places
|
||||
URL url=LeftImage.class.getClassLoader().getResource(LeftImage.filename); |
||||
if(url==null) url=LeftImage.class.getClassLoader().getResource("/data/"+LeftImage.filename); |
||||
|
||||
return new ImageIcon(url); |
||||
} |
||||
|
||||
public static final String filename="image.gif"; |
||||
} |
@ -0,0 +1,36 @@ |
||||
package totallynotmalware.ui; |
||||
|
||||
import javax.swing.BoxLayout; |
||||
import javax.swing.JFrame; |
||||
|
||||
import totallynotmalware.i18n.I18n; |
||||
|
||||
public class MainWindow extends JFrame { |
||||
|
||||
private static final long serialVersionUID = 2362142071956236158L; |
||||
|
||||
private BoxLayout layout; |
||||
private LeftImage leftImage; |
||||
private RightPanel rightPanel; |
||||
|
||||
public MainWindow() { |
||||
super(); |
||||
|
||||
this.layout=new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS); |
||||
|
||||
this.leftImage=new LeftImage(); |
||||
this.rightPanel=new RightPanel(); |
||||
|
||||
this.setLayout(this.layout); |
||||
|
||||
this.add(this.leftImage); |
||||
this.add(this.rightPanel); |
||||
|
||||
this.rightPanel.addButtonListener(new ButtonListener(this.rightPanel)); |
||||
|
||||
this.setTitle(I18n.get("title")); |
||||
this.pack(); |
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
this.setResizable(false); |
||||
} |
||||
} |
@ -0,0 +1,58 @@ |
||||
package totallynotmalware.ui; |
||||
|
||||
import java.awt.event.ActionListener; |
||||
|
||||
import javax.swing.BoxLayout; |
||||
import javax.swing.JButton; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.SwingConstants; |
||||
|
||||
import totallynotmalware.i18n.I18n; |
||||
|
||||
public class RightPanel extends JPanel { |
||||
|
||||
private static final long serialVersionUID = 7013073332645502179L; |
||||
|
||||
private BoxLayout layout; |
||||
private JLabel introLbl, questionLbl; |
||||
private FormPanel formPanel; |
||||
private JButton button; |
||||
|
||||
public RightPanel() { |
||||
super(); |
||||
|
||||
this.layout=new BoxLayout(this, BoxLayout.Y_AXIS); |
||||
|
||||
this.introLbl=new JLabel(I18n.get("text.intro"), SwingConstants.CENTER); |
||||
this.questionLbl=new JLabel(I18n.get("text.question"), SwingConstants.CENTER); |
||||
this.formPanel=new FormPanel(); |
||||
this.button=new JButton(I18n.get("button")); |
||||
|
||||
JPanel introPnl=new JPanel(); |
||||
introPnl.add(this.introLbl); |
||||
JPanel questionPnl=new JPanel(); |
||||
questionPnl.add(this.questionLbl); |
||||
JPanel buttonPnl=new JPanel(); |
||||
buttonPnl.add(this.button); |
||||
|
||||
this.setLayout(this.layout); |
||||
this.add(introPnl); |
||||
this.add(questionPnl); |
||||
this.add(this.formPanel); |
||||
this.add(buttonPnl); |
||||
} |
||||
|
||||
public String getCardNumber() { |
||||
return this.formPanel.getCardNumber(); |
||||
} |
||||
public String getCardDate() { |
||||
return this.formPanel.getCardDate(); |
||||
} |
||||
public String getCardCode() { |
||||
return this.formPanel.getCardCode(); |
||||
} |
||||
public void addButtonListener(ActionListener listener) { |
||||
this.button.addActionListener(listener); |
||||
} |
||||
} |
Loading…
Reference in new issue