放大小程序的图形大小
我想将小程序的大小加倍(包括位于其上的图形和组件)。
在我开始单独更改每个坐标之前,有什么简单的方法可以完成此任务吗?
I want to double the size of an applet (including the graphics and components positioned on it).
Is there any easy way to accomplish this before I start changing every coordinate individually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有写Java小程序了,所以我不能准确地告诉你哪些类和接口。
但作为一般原则,您可以使用装饰器来做到这一点。创建一个实现与图形上下文对象相同的接口的类*。将实际的图形上下文传递给类的构造函数。对于类中的每个方法,在其包装的图形上下文对象上调用相同的方法。并将放大倍率设置为该类的一个字段,以便将来可以将其设为 3 倍。
然后,当您的代码获取图形对象时,将其替换为自定义类的实例,该实例应包装图形对象。
如果这是不可能的,您可能必须破解您的原始代码。但请采纳我的建议 - 这次包含一个乘法因子作为变量/字段,以便下次您可以在一次位置调整数字。
It has been a while since I wrote a Java applet, so I cannot tell you exactly which classes and interfaces.
But as a general principle you could do this with a decorator. Make a class that implements the same interface as your graphics context object*. Pass the actual graphics context to the constructor of your class. For each method on your class, call the same method on the graphic context object that it wraps. And set the magnification as a field of the class so you can make it 3x in future.
Then, when your code takes the graphics object, replace that with an instance of your custom class, which should wrap the graphics object.
If this is not possible, you may have to hack your original code. But take my advice - this time include a multiplication factor as a variable/field so that next time you can adjust the number in once place.
如果小程序内容缩放,您只需更改嵌入 html 页面中小程序的大小。这假设仅使用了相对或计算的坐标和布局管理器。如果元素位于绝对位置,则这将不起作用。然后,您要么必须触摸代码,要么编写一个可缩放内容的包装器,正如 Joe 建议的那样。
If the applet contents scale you just need to change the size of the applet in the embedding html page. This assumes that only relative or calculated coordinates and layout managers have been used. If elements are positioned at absolute positions, this will not work will. Then you will either have to touch the code or write a wrapper that scales the content, as Joe suggested.