資源簡介
軟件設計模式作業(yè),要求用3個設計模式以上實現(xiàn)。代碼涉及了裝飾模式,工廠模式和適配器模式

代碼片段和文件信息
package?current;
import?javax.swing.*?;
import?java.awt.*;
import?java.awt.event.*;
import?other.Adapter;
import?other.xCoffeeCake;
public?class?Application?{
public?Application(){
Jframe?jf1;
JButton?jb1;
JButton?jb2;
JButton?jb3;
jf1=new?Jframe(“蛋糕售貨機“);
jb1=new?JButton(“水果蛋糕“);
jb2=new?JButton(“巧克力蛋糕“);
jb3=new?JButton(“水果和巧克力混合蛋糕“);
jf1.setLayout(new?GridLayout(31));
jf1.add(jb1);
jf1.add(jb2);
jf1.add(jb3);
jf1.pack();
jf1.setVisible(true);
jb1.addActionListener(new?ActionListener(){
public?void?actionPerformed(ActionEvent?e)?{
Jframe?jf2=new?Jframe(“結果“);
Cake?cake;
CakeFactory?cakefactory;
cakefactory=new?FruitCakeFactory();
cake=cakefactory.MakeCake(“水果蛋糕“);
JLabel?jlb=new?JLabel(cake.getCakeName());
jf2.add(jlb);
jf2.pack();
jf2.setVisible(true);
}
});
jb2.addActionListener(new?ActionListener(){
public?void?actionPerformed(ActionEvent?e){
xCoffeeCake?xcoffee=new?xCoffeeCake();?
Adapter?adapter=new?Adapter(xcoffee);
Jframe?jf3=new?Jframe(“結果“);
JLabel?jlb=new?JLabel(adapter.MakeCake(“巧克力蛋糕“).getCakeName());
jf3.add(jlb);
jf3.pack();
jf3.setVisible(true);
}
});
jb3.addActionListener(new?ActionListener(){
public?void?actionPerformed(ActionEvent?e){
CakeFactory?cakefactory;
cakefactory=new?FruitCakeFactory();
Cake?cake=cakefactory.MakeCake(“水果蛋糕“);
Cake?cake1=new?CakeDecorator(cake“和巧克力蛋糕混合蛋糕“);
Jframe?jf3=new?Jframe(“結果“);
JLabel?jlb=new?JLabel(cake1.getCakeName());
jf3.add(jlb);
jf3.pack();
jf3.setVisible(true);
}
});
}
public?static?void?main(String?args[]){
new?Application();
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????106650??2013-12-15?12:15??期末作業(yè)實驗報告.docx
?????文件????????301??2013-12-14?12:14??FinalText\.classpath
?????文件????????385??2013-12-14?12:14??FinalText\.project
?????文件?????????34??2013-12-14?12:17??FinalText\.reverse.properties
?????文件????????598??2013-12-14?12:14??FinalText\.settings\org.eclipse.jdt.core.prefs
?????文件???????1292??2013-12-14?17:28??FinalText\bin\current\Application$1.class
?????文件???????1331??2013-12-14?17:28??FinalText\bin\current\Application$2.class
?????文件???????1440??2013-12-14?17:28??FinalText\bin\current\Application$3.class
?????文件???????1322??2013-12-14?17:28??FinalText\bin\current\Application.class
?????文件????????298??2013-12-14?14:04??FinalText\bin\current\Cake.class
?????文件????????865??2013-12-15?12:02??FinalText\bin\current\CakeDecorator.class
?????文件????????330??2013-12-14?14:07??FinalText\bin\current\CakeFactory.class
?????文件????????458??2013-12-14?14:49??FinalText\bin\current\CoffeeCake.class
?????文件????????179??2013-12-14?16:11??FinalText\bin\current\CoffeeCakeFactory.class
?????文件????????537??2013-12-14?17:19??FinalText\bin\current\CoffeeCakeFactroy.class
?????文件????????414??2013-12-14?14:11??FinalText\bin\current\Decorator.class
?????文件????????455??2013-12-14?14:04??FinalText\bin\current\FruitCake.class
?????文件????????500??2013-12-14?14:08??FinalText\bin\current\FruitCakeFactory.class
?????文件????????624??2013-12-15?12:02??FinalText\bin\other\Adapter.class
?????文件????????517??2013-12-14?16:23??FinalText\bin\other\xCoffeeCake.class
?????文件????????185??2013-12-14?16:23??FinalText\bin\other\xCoffeeCakeFactory.class
?????文件???????1805??2013-12-14?17:28??FinalText\src\current\Application.java
?????文件?????????93??2013-12-14?14:04??FinalText\src\current\Cake.java
?????文件????????380??2013-12-15?12:02??FinalText\src\current\CakeDecorator.java
?????文件????????108??2013-12-14?14:07??FinalText\src\current\CakeFactory.java
?????文件????????195??2013-12-14?14:49??FinalText\src\current\CoffeeCake.java
?????文件????????102??2013-12-14?16:11??FinalText\src\current\CoffeeCakeFactory.java
?????文件????????206??2013-12-14?17:19??FinalText\src\current\CoffeeCakeFactroy.java
?????文件????????171??2013-12-14?14:11??FinalText\src\current\Decorator.java
?????文件????????181??2013-12-14?14:04??FinalText\src\current\FruitCake.java
............此處省略15個文件信息
評論
共有 條評論