?? advertiseclient.java
字號:
package client;
import agency.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class AdvertiseClient extends JPanel implements ActionListener
{
public static void main(String[] args) {
if (args.length!=0 && args.length!=3) {
System.err.println("Usage: AdvertiseClient AgencyJNDI AdvertiseJNDI AdvertiseJobJNDI");
System.exit(1);
}
final JFrame window = new JFrame("Agency Advertise Job");
try {
final AdvertiseClient client = new AdvertiseClient(args.length==3?args[0]:null, args.length==3?args[1]:null, args.length==3?args[2]:null);
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
client.shutdown();
window.dispose();
System.exit(0);
}
});
String title = client.getAgencyName();
window.setTitle(title);
Container cp = window.getContentPane();
cp.add(heading(title),BorderLayout.NORTH);
cp.add(client,BorderLayout.CENTER);
window.pack();
window.setVisible(true);
}
catch (Exception ex) {
System.err.println(ex);
window.dispose();
System.exit(1);
}
}
private static JLabel heading(String s) {
JLabel label = new JLabel(s,SwingConstants.CENTER);
Font old = label.getFont();
Font f = new Font(old.getName(),old.getStyle()|Font.BOLD|Font.ITALIC,(int)(old.getSize()*1.20));
label.setFont(f);
return label;
}
private String agencyJNDI = "java:comp/env/ejb/Agency";
private String advertiseJNDI = "java:comp/env/ejb/Advertise";
private String advertiseJobJNDI = "java:comp/env/ejb/AdvertiseJob";
private Agency agency;
private Advertise advertise;
private AdvertiseJob advertiseJob;
public AdvertiseClient(String agencyJNDI, String advertiseJNDI, String advertiseJobJNDI) {
if (agencyJNDI != null)
this.agencyJNDI = agencyJNDI;
if (advertiseJNDI != null)
this.advertiseJNDI = advertiseJNDI;
if (advertiseJobJNDI != null)
this.advertiseJobJNDI = advertiseJobJNDI;
try
{
setLayout(new BorderLayout());
agency = getAgency(this.agencyJNDI);
loadTables(agency);
Box b = Box.createHorizontalBox();
b.add (nwPanel());
b.add (nePanel());
add (b, BorderLayout.NORTH);
add (mainPanel(), BorderLayout.CENTER);
add (jobPanel(), BorderLayout.SOUTH);
loginButton.addActionListener(this);
logoffButton.addActionListener(this);
registerButton.addActionListener(this);
updateButton.addActionListener(this);
deleteButton.addActionListener(this);
selectJobButton.addActionListener(this);
allJobs.addActionListener(this);
createJobButton.addActionListener(this);
addSkillButton.addActionListener(this);
removeSkillButton.addActionListener(this);
updateJobButton.addActionListener(this);
deleteJobButton.addActionListener(this);
currentJob.setEnabled(false);
enableForm(false);
}
catch (NamingException ex) {
abort("getAgency",ex.toString());
}
catch (CreateException ex) {
abort("getAgency",ex.toString());
}
catch (RemoteException ex) {
abort("getAgency",ex.toString());
}
catch (ClassCastException ex) {
abort("getAgency",ex.toString());
}
}
private FixedField login = new FixedField(16);
private FixedField addLogin = new FixedField(16);
private FixedField addName = new FixedField(16);
private FixedField addEmail = new FixedField(16);
private FixedField name = new FixedField(16);
private FixedField email = new FixedField(16);
private FixedField address1 = new FixedField(16);
private FixedField address2 = new FixedField(16);
private FixedField newJob = new FixedField(16);
private DefaultComboBoxModel jobs = new DefaultComboBoxModel();
private JComboBox allJobs = new JComboBox();
private FixedField currentJob = new FixedField(16);
private JTextArea description = new JTextArea(4,32);
private JComboBox location;
private JList allSkills;
private DefaultListModel skills = new DefaultListModel();
private JList actualSkills = new JList(skills);
private JButton loginButton = new JButton("Login");
private JButton logoffButton = new JButton("Logoff");
private JButton updateButton = new JButton("Update");
private JButton deleteButton = new JButton("Delete Customer");
private JButton registerButton = new JButton("Register");
private JButton selectJobButton = new JButton("Select Job");
private JButton createJobButton = new JButton("Create Job");
private JButton addSkillButton = new JButton("Add skill");
private JButton removeSkillButton = new JButton("Remove skill");
private JButton updateJobButton = new JButton("Update Job");
private JButton deleteJobButton = new JButton("Delete Job");
private JPanel boxPanel(String name) {
JPanel p = new JPanel();
Border border = BorderFactory.createEtchedBorder();
border = BorderFactory.createTitledBorder(border,name);
p.setLayout (new BoxLayout(p,BoxLayout.Y_AXIS));
p.setBorder(border);
return p;
}
private JPanel panelRow(JComponent l, JComponent r) {
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
p.add (l);
if (r != null)
p.add (r);
return p;
}
private JPanel nwPanel() {
JPanel panel = boxPanel("Login");
panel.add (panelRow(new FixedLabel("Login name:"),login));
panel.add (Box.createVerticalGlue());
panel.add(panelRow(loginButton,logoffButton));
return panel;
}
private JPanel nePanel() {
JPanel panel = boxPanel("Register");
panel.add (panelRow(new FixedLabel("Login name:"),addLogin));
panel.add (panelRow(new FixedLabel("Full name:"),addName));
panel.add (panelRow(new FixedLabel("Email address:"),addEmail));
panel.add (Box.createVerticalGlue());
panel.add(panelRow(registerButton,null));
return panel;
}
private JPanel mainPanel() {
JPanel panel = boxPanel("Customer details");
Box b = Box.createHorizontalBox();
Box left = Box.createVerticalBox();
left.add (panelRow(new FixedLabel("Full name:"),name));
left.add (panelRow(new FixedLabel("Email address:"),email));
left.add (panelRow(new FixedLabel("Address 1:"),address1));
left.add (panelRow(new FixedLabel("Address 2:"),address2));
left.add (Box.createVerticalGlue());
left.add(panelRow(updateButton,deleteButton));
Box right = Box.createVerticalBox();
right.add (panelRow(new FixedLabel("Jobs:"),allJobs));
right.add(panelRow(selectJobButton,null));
right.add (Box.createVerticalGlue());
right.add (panelRow(new FixedLabel("New Job Ref:"),newJob));
right.add(panelRow(createJobButton,null));
b.add (left);
b.add (Box.createHorizontalGlue());
b.add (right);
panel.add(b);
return panel;
}
private JPanel jobPanel() {
actualSkills.setVisibleRowCount(4);
JPanel panel = boxPanel("Job details");
Box left = Box.createVerticalBox();
left.add (panelRow(new FixedLabel("Reference:"),currentJob));
left.add (panelRow(new FixedLabel("Location:"),location));
left.add(panelRow(new FixedLabel("Skills:"),new JScrollPane(actualSkills)));
left.add(panelRow(new FixedLabel(""),removeSkillButton));
Box right = Box.createVerticalBox();
right.add (panelRow(new FixedLabel("Description:"),new JScrollPane(description)));
right.add(panelRow(new FixedLabel("Available skills:"),new JScrollPane(allSkills)));
right.add(panelRow(new FixedLabel(""),addSkillButton));
Box t = Box.createHorizontalBox();
t.add (left);
t.add (Box.createHorizontalGlue());
t.add (right);
panel.add(t);
panel.add (Box.createVerticalGlue());
panel.add(panelRow(updateJobButton,deleteJobButton));
return panel;
}
public void actionPerformed(ActionEvent ev) {
try {
Object o = ev.getSource();
if (o == loginButton)
doLogin();
else if (o == logoffButton)
doLogoff();
else if (o == updateButton)
doUpdate();
else if (o == registerButton)
doRegister();
else if (o == deleteButton)
doDelete();
else if (o == selectJobButton || o == allJobs)
doJobSelect();
else if (o == createJobButton)
doJobCreate();
else if (o == updateJobButton)
doJobUpdate();
else if (o == deleteJobButton)
doJobDelete();
else if (o == addSkillButton)
doAddSkill();
else if (o == removeSkillButton)
doRemoveSkill();
else
warning("Unknown event","Unknown event: "+ev);
}
catch (NamingException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (CreateException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (NotFoundException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (DuplicateException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (RemoveException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (RemoteException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (ClassCastException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
}
public void shutdown() {
try {
if (advertiseJob != null)
advertiseJob.remove();
if (advertise != null)
advertise.remove();
if (agency != null)
agency.remove();
}
catch (RemoveException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
catch (RemoteException ex) {
error("actionPerformed",ex.toString());
ex.printStackTrace();
}
}
private void enableForm(boolean on)
{
loginButton.setEnabled(!on);
logoffButton.setEnabled(on);
updateButton.setEnabled(on);
deleteButton.setEnabled(on);
allJobs.setEnabled(on);
selectJobButton.setEnabled(on);
createJobButton.setEnabled(on);
login.setEnabled(!on);
enableJobForm(false);
}
private void enableJobForm(boolean on)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -