flash打开文件时缺少文字_Flash:TextField字体不显示/文字不显示/文字丢失

[ Embed(source= "../lib/font1.swf")]private varFont1:Class;

[ Embed(source= "../lib/font2.swf")]private varFont2:Class;public functionTest2()

{//第一种嵌入方式(运行时加载swf)

var loader1:Loader = newLoader();

loader1.load(new URLRequest("font1.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));

addChild(loader1);var loader2:Loader = newLoader();

loader2.load(new URLRequest("font2.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));

addChild(loader2);

loader2.x= 300;

setTimeout(function():void{

TextField(MovieClip(MovieClip(loader1.content). getChildAt(0)).getChildAt (0)).text = "一二三四五六";

TextField(MovieClip(MovieClip(loader2.content). getChildAt(0)).getChildAt (0)).text = "一二三四五六";

},1000);//第二种嵌入方式(加入swc)

var text1:MovieClip = newTestFont1();

addChild(text1);

text1.y= 50;

TextField(text1. getChildAt(0)).text = "一二三四五六";var text2:MovieClip = newTestFont2();

addChild(text2);

text2.x= 300;

text2.y= 50;

TextField(text2. getChildAt(0)).text = "一二三四五六";//第三种嵌入方式(编译时嵌入swf)

var text3:MovieClip = newFont1();

addChild(text3);

text3.y= 100;var text4:MovieClip = newFont2();

addChild(text4);

text4.x= 300;

text4.y= 100;

setTimeout(function():void{//text3是封装的一个壳,子元件是loader,loader里边才是这个swf

Object(text3).getChildAt(0).content. getChildAt(0).getChildAt(0).text = "一二三四五六";Object(text4).getChildAt(0).content. getChildAt(0).getChildAt(0).text = "一二三四五六";

},1000);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以这样写一个简单的计算器: ```java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Calculator extends JFrame implements ActionListener { private JTextField textField; private JButton[] buttons; private String[] buttonLabels = { "7", "8", "9", "+", "4", "5", "6", "-", "1", "2", "3", "*", "0", "/", ".", "=" }; private JPanel buttonPanel; public Calculator() { super("Calculator"); // 设置窗口大小和位置 setSize(300, 400); setLocationRelativeTo(null); // 创建文本框和按钮 textField = new JTextField(); buttons = new JButton[buttonLabels.length]; for (int i = 0; i < buttons.length; i++) { buttons[i] = new JButton(buttonLabels[i]); buttons[i].addActionListener(this); } // 创建按钮面板并添加按钮 buttonPanel = new JPanel(new GridLayout(4, 4)); for (JButton button : buttons) { buttonPanel.add(button); } // 将文本框和按钮面板添加到窗口中 add(textField, BorderLayout.NORTH); add(buttonPanel); // 显示窗口 setVisible(true); } public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); if (action.equals("=")) { try { // 计算表达式 String expression = textField.getText(); double result = evaluate(expression); textField.setText(Double.toString(result)); } catch (ArithmeticException ex) { // 处理除数为零的情况 textField.setText("除数不能为零"); } catch (Exception ex) { // 处理其他异常 textField.setText("Error"); } } else { // 添加数字或运算符 textField.setText(textField.getText() + action); } } private double evaluate(String expression) { // 将表达式转换为逆波兰表达式 String[] tokens = expression.split(" "); Stack<Double> stack = new Stack<>(); for (String token : tokens) { if (token.equals("+")) { double a = stack.pop(); double b = stack.pop(); stack.push(a + b); } else if (token.equals("-")) { double a = stack.pop(); double b = stack.pop(); stack.push(b - a); } else if (token.equals("*")) { double a = stack.pop(); double b = stack.pop(); stack.push(a * b); } else if (token.equals("/")) { double a = stack.pop(); double b = stack.pop(); if (a == 0) { throw new ArithmeticException(); } stack.push(b / a); } else { double number = Double.parseDouble(token); stack.push(number); } } // 计算逆波兰表达式的值 double result = stack.pop(); if (!stack.isEmpty()) { throw new RuntimeException(); } return result; } public static void main(String[] args) { new Calculator(); } } ``` 当输入 `3/0` ,会抛出 `ArithmeticException` 异常,我们在 `actionPerformed` 方法中捕获这个异常并显示提示信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值