public class MailNoticeFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static int index=0;
private static MailNoticeFrame instance = null;
public static Workspace w = SparkManager.getWorkspace();
public static JButton jb = new JButton("下一条");
public static JButton button_left = new JButton("上一条");
public static JButton button_right = new JButton("下一条");
public static JButton button_end = new JButton("查看全部");
private MailNoticeFrame() {
super();
}
public static synchronized MailNoticeFrame getInstance() {
if (instance == null) {
instance = new MailNoticeFrame();
instance.setSize(400, 400);
instance.setLocation(400, 700);
instance.setTitle("您有新邮件");
instance.setVisible(true);
button_left.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
if(index>0){
index--;
addComponentsToPane(instance);
}
}
});
button_right.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
if(index<w.lmb.size()-1){
index++;
addComponentsToPane(instance);
}
}
});
}
if (w.lmb.size() > 1) {
addComponentsToPane(instance.getContentPane());
}
instance.setVisible(true);
return instance;
}
public static void addComponentsToPane(Container pane) {
// JTextArea jta0=new JTextArea(w.lmb.get(0).getFromUser());
// jta0.setLineWrap(true);
// pane.add(jta0, BorderLayout.PAGE_START);
JTextArea jta = new JTextArea(w.lmb.get(index).getTitle() + "\r\n\r\n\r\n");
jta.append(w.lmb.get(index).getUrl());
jta.setLineWrap(true);
jta.setEditable(false);
jta.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
try {
if(e.getClickCount()==2){
BrowserLauncher.openURL(w.lmb.get(index).getUrl()
.substring(w.lmb.get(index).getUrl().indexOf("http")));
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
pane.add(jta, BorderLayout.CENTER);
pane.add(button_left, BorderLayout.LINE_START);
pane.add(button_right, BorderLayout.LINE_END);
pane.add(button_end, BorderLayout.PAGE_END);
}
}
获取这个实例时间是在Workspace 类的消息监听器里面调用getInstance()的,现在的问题是:
1.消息一接收完,上一条和下一条按钮都无效了。。
2.有时候界面会出现错误,我一开始按钮添加也进行判断后调整大小时会出现按钮不见,文本位置出错等错误,一改变消息提示框大小就会出现布局上的错误。
3.消息接收期间,焦点会变为这个消息提示框,如何解决这问题。
w.lmb是消息列表,我用来存放消息的,是个静态成员变量 |
|