我必须创建两个JLabel,并且应该在JFrame中定位在中心和正下方.我正在使用摆动的gridbaglayout,但我无法弄清楚如何做到这一点.
terminalLabel = new JLabel("No reader connected!", SwingConstants.CENTER);
terminalLabel.setVerticalAlignment(SwingConstants.TOP);
cardlabel = new JLabel("No card presented", SwingConstants.CENTER);
cardlabel.setVerticalAlignment(SwingConstants.BOTTOM);
Run Code Online (Sandbox Code Playgroud) 我有一个这样的方法:
public int getIncrement() {
String extractFolder = "/mnt/sdcard/MyFolder";
boolean newFolder = new File(extractFolder).mkdir();
int counter = 0;
try {
File root = new File(extractFolder);
if (root.canWrite()){
File gpxfile = new File(root, "gpxfile.txt");
FileWriter gpxwriter = new FileWriter(gpxfile);
BufferedWriter out = new BufferedWriter(gpxwriter);
Scanner scanner = new Scanner(new FileInputStream(gpxfile.getAbsolutePath()), "UTF-8");
Log.i("PATH: ", extractFolder + "/gpxfile.txt");
while(scanner.hasNextLine()) {
String inc = scanner.nextLine();
counter = Integer.parseInt(inc);
Log.i("INSIDE WHILE: ", Integer.toString(counter));
}
counter++;
out.write(Integer.toString(counter));
out.close();
}
} catch (IOException e) {
Log.e("GEN_PCN: ", …Run Code Online (Sandbox Code Playgroud) 我的主要活动中有一个线程,它将创建类的对象 SendMail
package Logic;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import android.util.Log;
public class SendMail {
String from;
String to;
String subject;
String bodyText;
String fileName;
public SendMail(String to, String fileName, String PCN) {
this.to = to;
this.fileName = fileName;
this.from = "Hello@gmail.com";
this.bodyText = "FILE";
this.subject = PCN;
}
public void sendMailWithAttatchment() {
Properties properties = new …Run Code Online (Sandbox Code Playgroud) 我有一个带边框的 UserControl,边框的颜色应该使用依赖属性设置。我还想为边界的不透明度设置动画。我当前的 xaml 代码如下所示:
<Border BorderBrush="{Binding ElementName=ImageViewerUserControl,
Path=NotificationColor}" BorderThickness="3" x:Name="AnimatedBorderBrush"
Visibility="{Binding ElementName=ImageViewerUserControl,
Path=ShowSequenceErrorNotification, Converter={StaticResource boolToVisibility}}">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="AnimatedBorderBrush"
Storyboard.TargetProperty="BorderBrush.Opacity"
RepeatBehavior="Forever"
AutoReverse="True"
From="1"
To="0.0"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
</Border>
Run Code Online (Sandbox Code Playgroud)
这只会给出错误:
无法解析属性路径“BorderBrush.Opacity”中的所有属性引用。验证适用对象是否支持这些属性。
但是,如果我将 BorderBrush 的颜色更改为,可以说它Black有效。这怎么可能实现?我想通过依赖属性设置边框的 Brush 颜色。是的,依赖属性是Brush
我有一个支持OBEX对象推送配置文件的设备,此配置文件基于串行端口配置文件.我的猜测是我可以使用Android蓝牙聊天示例将此设备连接到我的Android手机.但是我遇到了一个问题,关于socket.accept()android SDK中的功能.我尝试完成将手机连接到此设备,如下所示:
adapter = BluetoothAdapter.getDefaultAdapter();
device = adapter.getRemoteDevice("00:1B:DC:0F:EC:7E");
AcceptThread = new AcceptThread(true, adapter, device);
AcceptThread.start();
Run Code Online (Sandbox Code Playgroud)
AcceptThread中的构造函数编码如下:
public AcceptThread(boolean secure, BluetoothAdapter adapter, BluetoothDevice device) {
BluetoothServerSocket tmp = null;
this.adapter = adapter;
this.device = device;
// Create a new listening server socket
try {
tmp = adapter.listenUsingInsecureRfcommWithServiceRecord(device.getName(), UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (Exception e) {
Log.e(TAG, ".AcceptThread # listen() failed", e);
}
mmServerSocket = tmp;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试connect()按照我之前说过做的时候
public void run() {
BluetoothSocket socket = null;
// Listen to the …Run Code Online (Sandbox Code Playgroud) 我有一个文件夹,其中包含一些我想在处理后删除的文件.文件有扩展名.FIR在一些谷歌搜索后,我找到了一个我修改过的递归方法:
void delete(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
if(f.listFiles().toString().contains(".FIR"))
delete(c);
}
if (!f.delete())
throw new FileNotFoundException("Failed to delete file: " + f);
}
Run Code Online (Sandbox Code Playgroud)
此函数将抛出IOException告诉我:
07-31 11:02:31.885: E/DELETE:(5694): Failed to delete file: /mnt/sdcard/ExtractedFiles
Run Code Online (Sandbox Code Playgroud)
该文件夹已设置为RW操作.在我的清单文件中:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)
我找不到另一个听起来类似的许可 MODIFY_FILES
有任何想法吗?
我已经定义了我的设置活动的布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<PreferenceCategory
android:title="Second Category"
android:key="second_category">
<EditTextPreference
android:id="@+id/pcnSetting"
android:key="pcn"
android:title="Set Canton Digits"
android:summary="Define your canton digits"
android:dialogTitle="Set Canton Digits"
android:dialogMessage="Please add your canton digits"
android:inputType="number"
android:imeOptions="actionDone"
android:maxLength="4"/>
</PreferenceCategory>
Run Code Online (Sandbox Code Playgroud)
我想导入EditTextPreference到我的java代码,只是为了确保用户键入至少和最多4位数.
这就是我尝试EditTextPreference进入java的方式
canton = (EditTextPreference)findViewById(R.id.pcnSetting);
Run Code Online (Sandbox Code Playgroud)
但是Eclipse给了我这个错误:
Cannot cast from View to EditTextPreference
Run Code Online (Sandbox Code Playgroud)
为什么会这样?如何检查用户输入的内容是否至少最大4 int's?
我的原始布局xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:background="#e4e8ed"
android:orientation="vertical"
android:padding="0px" >
<include
android:id="@+id/tabBar"
layout="@layout/tab" />
<Button
android:id="@+id/nist"
android:layout_width="301dp"
android:layout_height="63dp"
android:text="Generate NIST file" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rectangle"
android:layout_width="276dp"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:layout_gravity="center_horizontal">
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="128dp"
android:text="Button" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但是,如果我移动Button内部LinearLayout我的应用程序只是抛出异常:
LinearLayout cannot be cast to android.widget.Button
Run Code Online (Sandbox Code Playgroud)
我觉得这很奇怪,我怎么能这样做?
编辑:
这是我将按钮"导入"到我的java代码的方式:
setTabBar(R.layout.horz_scroll_app);
nist = (Button) findViewById(R.id.nist);
Run Code Online (Sandbox Code Playgroud)
该setTabBar方法:
public void setTabBar(int id) {
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = …Run Code Online (Sandbox Code Playgroud) 我的ProgressDialog有一个自定义动画,其设置方式如下:
pd.setIndeterminateDrawable(c.getResources().getDrawable(R.anim.progress_animation));
Run Code Online (Sandbox Code Playgroud)
该progress_animation是这样的:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="358" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:centerColor="#4c737373"
android:centerY="0.50"
android:endColor="#E66A0F"
android:startColor="#4c737373"
android:type="sweep"
android:useLevel="false" />
</shape>
</animated-rotate>
Run Code Online (Sandbox Code Playgroud)
这会给我一个橙色的纺车,但是它比ProgressDialog中的默认纺车“慢”或更慢。我尝试将android:toDegrees360 设置为358,但没有运气。我还启用了硬件加速。无论如何,我可以使此动画更流畅或更快速吗?
谢谢!
使用caliburn micro,您可以执行以下操作来执行方法:
<Buttton x:Name="ClickMe" />
Run Code Online (Sandbox Code Playgroud)
并ViewModel具有这样的方法:
public void ClickMe()
{
//Method will be execute upon button click
}
Run Code Online (Sandbox Code Playgroud)
是否可以将此绑定到属性中的方法上ViewModel?像这样?:
<Buttton x:Name="Model.ClickMe" />
Run Code Online (Sandbox Code Playgroud)