Swing MVC 简单源码
解决方案 »
- 哪个大牛帮我看下这个运行错误该咋解决呢
- 2个系统之间数据传输问题
- 数据库连接池讨论 C3P0 or dbcp or proxool or .................散分讨论
- 如何获得当前日期并显示在GUI组件中显示
- java 中的字符都是以Unicode进行编码的,那么在字节流中
- 招聘.net winform开发人员
- 第一次编程,百鸡问题,请帮帮忙!
- [JAVA bug?] Applet在Linux下焦点丢失问题。
- jbuilder 6.0 的注册问题
- 在windows下怎么设置支持Java Server Let的Web Server?
- 如何控制内部窗体不重复弹出
- 新鲜出炉的用JAVA写的小游戏..点点世界V1.0发布!
private int size = 20;
private int style = 20; public M() {
} public int getSize() {
return size;
} public void setSize(int size) {
this.size = size;
} public int getStyle() {
return style;
} public void setStyle(int style) {
this.style = style;
}}import java.awt.Button;
import java.awt.Container;
import java.awt.Font;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SpringLayout;public class V { // TITLE
final private static String MENU_DLG_TITLE = "MVC"; // Frame
private JFrame frame = new JFrame(MENU_DLG_TITLE); // Container
private Container con = frame.getContentPane(); Font font = new Font("test", 20, 20); JLabel lable = new JLabel(font.getName());
Button enlarge = new Button("enlarge");
Button abridge = new Button("abridge"); public V() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SpringLayout lay = new SpringLayout();
con.setLayout(lay); lay.putConstraint(SpringLayout.WEST, lable, 120,SpringLayout.WEST, con);
lay.putConstraint(SpringLayout.NORTH, lable, 180, SpringLayout.NORTH, con); lay.putConstraint(SpringLayout.WEST, enlarge, 80, SpringLayout.WEST, con);
lay.putConstraint(SpringLayout.NORTH, enlarge, 380, SpringLayout.NORTH, con); lay.putConstraint(SpringLayout.WEST, abridge, 140, SpringLayout.WEST,con);
lay.putConstraint(SpringLayout.NORTH, abridge, 380, SpringLayout.NORTH, con); con.add(lable);
con.add(enlarge);
con.add(abridge); C c = new C(this, new M()); enlarge.addActionListener(c);
abridge.addActionListener(c); frame.setBounds(520, 80, 300, 450);
frame.setVisible(true);
} public Button getEnlarge() {
return enlarge;
} public void setEnlarge(Button enlarge) {
this.enlarge = enlarge;
} public Button getAbridge() {
return abridge;
} public void setAbridge(Button abridge) {
this.abridge = abridge;
} public JFrame getFrame() {
return frame;
} public void setFrame(JFrame frame) {
this.frame = frame;
} public Container getCon() {
return con;
} public void setCon(Container con) {
this.con = con;
} public JLabel getLable() {
return lable;
} public void setLable(JLabel lable) {
this.lable = lable;
}}import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class C implements ActionListener{
private V v ;
private M m; public C(V v,M m){
this.v = v;
this.m = m;
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == v.getEnlarge()) {
m.setSize(m.getSize() + 5);
m.setStyle(m.getStyle() + 5);
}else{
m.setSize(m.getSize() - 5);
m.setStyle(m.getStyle() - 5);
}
System.out.println("m.Style:" + m.getStyle());
System.out.println("m.Size:" + m.getSize());
Font font = new Font(v.getLable().getText(),m.getStyle(),m.getSize());
v.getLable().setFont(font); } public V getV() {
return v;
} public void setV(V v) {
this.v = v;
} public M getM() {
return m;
} public void setM(M m) {
this.m = m;
}
}public class Test { public static void main(String[] args) {
M m = new M();
V v = new V();
new C(v,m);
}
}
四个类 运行 Test就OK