小编Mat*_*lor的帖子

paintComponent是如何工作的?

这可能是一个非常无聊的问题.我刚刚开始学习Java

我不明白paintComponent方法的操作.我知道如果我想画一些东西,我必须覆盖paintComponent方法.

public void paintComponent(Graphics g)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

但它何时被称为?我从来没有看到像"object.paintComponent(g)"这样的东西,但它仍然是在程序运行时绘制的.

什么是Graphics参数?这个从哪里来?调用方法时必须提供参数.但正如我之前所说,似乎永远不会明确地调用此方法.那么谁提供这个参数呢?为什么我们必须将其转换为Graphics2D?

public void paintComponent(Graphics g)
{
    ...
    Graphics2D g2= (Graphics2D) g;
    ...
}
Run Code Online (Sandbox Code Playgroud)

java swing paintcomponent

61
推荐指数
2
解决办法
12万
查看次数

在特征上设置通知会导致无效句柄错误

使用CoreBluetooth我想将数据从iPhone发送到Mac.为此,我编写了像iPhone一样的代码作为'Peripheral'和Mac作为'Central'.

它工作得很好,但有时会直接断开连接,然后连续连接和断开连接.

有时当它试图重新连接时,在中心它直接调用'didDisconnectPeripheral'委托方法.但有时它在'didUpdateNotificationStateForCharacteristic'中有错误"句柄无效".

我在网上提到了所有的链接.但我无法解决这个问题.我在iPhone中认为它存储了蓝牙缓存.

请提出解决方法如何解决"句柄无效"错误?

以下是一些重要的方法.

对于Peripheral,我写了如下代码.

在Appdelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.peripheral = [[PeripheralServerObject alloc] init];
self.peripheral.serviceUUID = [CBUUID UUIDWithString:@"4w24"];
return YES;
}
Run Code Online (Sandbox Code Playgroud)

在外围对象文件中:

//To Check Bluetooth State
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
    switch (peripheral.state) {
        case CBPeripheralManagerStatePoweredOn:
            [self enableService];
            break;
        case CBPeripheralManagerStatePoweredOff: {
            [self disableService];
            break;
        }
}

// To Add characteristics to Service
- (void)enableService
{
[self.peripheral removeAllServices];
 self.service = [[CBMutableService alloc]
                    initWithType:self.serviceUUID primary:YES];

self.authChar =
        [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"a86e"]
                                           properties:CBCharacteristicPropertyNotify
                                                value:nil
                                          permissions:CBAttributePermissionsReadable];


self.respChar =
        [[CBMutableCharacteristic …
Run Code Online (Sandbox Code Playgroud)

macos bluetooth objective-c ios core-bluetooth

57
推荐指数
1
解决办法
2646
查看次数

layout_gravity无法在水平线性布局中工作

我一直试图layout_gravity在横向使用linear layout.但它似乎没有用.我希望使用relative layout或任何其他布局.我想知道为什么它不与工作linear layout.我刚才使用layout_gravityvertical线性布局,它在我的预期的方式工作过.

<LinearLayout
    android:id="@+id/shata"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <TextView
        android:id="@+id/title_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/black"
        android:text="shata1"
        android:textAppearance="?android:attr/textAppearanceMedium"
        />
    <TextView
        android:id="@+id/map_imageview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="shata2"/>    
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,线性布局有一个orientation=horizontalwidth=match_parent(它只是在根布局内).但是,LinearLayout尽管我已经分别给出了它们layout_gravity=center,但两个TextView都显示在左侧layout_gravity=right.

android android-linearlayout

21
推荐指数
2
解决办法
2万
查看次数

使用Scotty的网络I/O的吞吐量意外低

我试图对Scotty进行测试,以测试网络I/O效率和整体吞吐量.

为此,我设置了两个用Haskell编写的本地服务器.一个不做任何事情而只是充当API的人.

代码相同

{-# LANGUAGE OverloadedStrings #-}


import Web.Scotty

import Network.Wai.Middleware.RequestLogger 

import Control.Monad
import Data.Text
import Control.Monad.Trans
import Data.ByteString
import Network.HTTP.Types (status302)
import Data.Time.Clock
import Data.Text.Lazy.Encoding (decodeUtf8)
import Control.Concurrent
import Network.HTTP.Conduit
import Network.Connection (TLSSettings (..))
import Network.HTTP.Client
import Network
main = do 
  scotty 4001 $ do
    middleware logStdoutDev
    get "/dummy_api" $ do
        text $ "dummy response"
Run Code Online (Sandbox Code Playgroud)

我写了另一个调用此服务器并返回响应的服务器.

{-# LANGUAGE OverloadedStrings #-}


import Web.Scotty

import Network.Wai.Middleware.RequestLogger 

import Control.Monad
import Control.Monad.Trans
import qualified Data.Text.Internal.Lazy as LT
import Data.ByteString
import Network.HTTP.Types (status302)
import …
Run Code Online (Sandbox Code Playgroud)

benchmarking haskell http-conduit scotty

16
推荐指数
1
解决办法
334
查看次数

Android构建过程如何工作?

我发现了一篇关于Android构建过程如何工作的好文章,其中显示了以下过程:

在此输入图像描述

但是,我也看到了另一篇文章它说,它使用javac的所有文件转换成.class文件,然后dx tooladk将所有.class的文件classes.dex,就像这样:

在此输入图像描述

请有人澄清哪一个是正确的?

android android-build

14
推荐指数
1
解决办法
8170
查看次数

如何在相机应用程序中添加矩形叠加?

如何在相机预览中添加矩形叠加(应该更像矩形框)?我的应用程序包含一个按钮,可在单击时打开相机.我需要相机预览中的叠加层.

java文件的代码是:

    public class MainActivity extends Activity {
     Button b;
     Intent i;
     Bitmap bmp;
     final static int cameraData = 0;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         b = (Button) findViewById(R.id.button);
         InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
         bmp = BitmapFactory.decodeStream(is);
         b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            // TODO Auto-generated method stub
            i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(i, cameraData);

        }
    });
 }
}
Run Code Online (Sandbox Code Playgroud)

布局文件如下:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_gravity="center"
    android:text="click to …
Run Code Online (Sandbox Code Playgroud)

android overlay android-camera

8
推荐指数
2
解决办法
4万
查看次数

getModifiers()方法如何计算多个修饰符的值?

getModifiers()的Java Doc 如下:

int getModifiers()

以整数形式返回此Member表示的成员或构造函数的Java语言修饰符.应使用Modifier类来解码整数中的修饰符.

和Java Docs还提供了不同修饰符及其对应的int值列表:

public static final int ABSTRACT 1024

public static final int FINAL 16

public static final int INTERFACE 512

public static final int NATIVE 256

public static final int PRIVATE 2

public static final int PROTECTED 4

public static final int PUBLIC 1

public static final int STATIC 8

public static final int STRICT 2048

public static final int SYNCHRONIZED 32

public static final int TRANSIENT 128

public …

java

7
推荐指数
1
解决办法
4251
查看次数

如何在SurfaceView中动态更改图像?

我使用的是默认的SurfaceView实现,代码可以在这里找到(这是一个手指绘图的应用程序示例,我只是禁用它并绘制图像).有3个主要的独立课程 -

  1. 活动类(SurfaceViewSampleActivity)
  2. SurfaceView(CanvasView)
  3. 线程类(UIThread).

SurfaceView绘制在构造函数中设置的图像(Bitmap).我还实现了用户可以调用相机应用程序并拍照的功能.图片必须交换默认图像(在SurfaceView构造函数集图像上).

我试图在我的活动类中创建一个简单的方法并设置位图,但这不起作用:

private void setImage() {
    view.bitmap = this.mImageBitmap; 

}
Run Code Online (Sandbox Code Playgroud)

我以为SurfaceView线程可能正在使用位图,所以我试图锁定变量:

private void setImage() {   
    synchronized (view.bitmap) {
        view.bitmap = this.mImageBitmap;
    }   
}
Run Code Online (Sandbox Code Playgroud)

应用程序也崩溃了.

SurfaceView绘制方法:

protected void onDraw(Canvas canvas) {
    setPaintProperties();

    if (canvas != null) {
        canvas.drawColor(Color.WHITE);

        synchronized ( this.bitmap ) {
            canvas.drawBitmap(this.bitmap, 0, 0, new Paint() );
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在调用构造函数更改SurfaceView中的位图变量?

multithreading android surfaceview

6
推荐指数
1
解决办法
1917
查看次数

Notepad ++中有多个垂直边

在"设置" - >"首选项" - >"编辑"中,您可以显示垂直边缘以指示您不希望超出的列宽.

我现在有一个80个字符,但我也想添加一个120个字符作为编码标准,我坚持对不同的语言有不同的行限制.但是,我似乎无法找到原生设置或插件,这使我可以有多个垂直边缘(蛋糕上的樱桃也将使它们具有不同的颜色).

我在网上进行了广泛的搜索,但似乎找不到任何东西.还有其他人找到了办法吗?

coding-style notepad++

5
推荐指数
0
解决办法
574
查看次数

使用AssetManager时,位图字体颠倒

今天我开始使用AssetManagerfrom libGDX来加载我的资产.在此之前我已经在一个单独的类中加载了所有内容,但我没有使用AssetManager.
我目前如何加载位图字体:

manager.load("font/good_neighbors_unity.fnt", BitmapFont.class);
[...]
bFont = manager.get("font/good_neighbors_unity.fnt", BitmapFont.class);
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我使用Asset Manager加载时,我使用的位图字体是颠倒的.这是因为在我的正交相机中,y指向下方.在Bitmap Font构造函数中有一个布尔值来翻转字体并避免此问题.但是当我加载它时似乎没有这样的选项AssetManager.可能有一个相对简单的解决方案,但我找不到任何允许我翻转字体的方法.有没有一个选项允许我在使用时翻转位图字体AssetManager

java fonts bitmap libgdx

3
推荐指数
1
解决办法
234
查看次数